Module: kamailio
Branch: master
Commit: ad687875c190e863d45a99f5d77422dde37223f7
URL:
https://github.com/kamailio/kamailio/commit/ad687875c190e863d45a99f5d77422d…
Author: Pantelis Kolatsis <pk(a)gilawa.com>
Committer: Henning Westerholt <hw(a)gilawa.com>
Date: 2023-04-21T17:33:17Z
xprint: convert to memory logging helper, improve mem error handling
---
Modified: src/modules/xprint/xp_lib.c
Modified: src/modules/xprint/xprint.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ad687875c190e863d45a99f5d77422d…
Patch:
https://github.com/kamailio/kamailio/commit/ad687875c190e863d45a99f5d77422d…
---
diff --git a/src/modules/xprint/xp_lib.c b/src/modules/xprint/xp_lib.c
index 3b1c59e57cc..6e6417ae736 100644
--- a/src/modules/xprint/xp_lib.c
+++ b/src/modules/xprint/xp_lib.c
@@ -1062,7 +1062,17 @@ static int _xl_parse_format(char *s, xl_elog_p *el, int shm,
xl_parse_cb parse_c
else
e = pkg_malloc(sizeof(xl_elog_t));
if(!e)
+ {
+ if(shm)
+ {
+ SHM_MEM_ERROR;
+ }
+ else
+ {
+ PKG_MEM_ERROR;
+ }
goto error;
+ }
memset(e, 0, sizeof(xl_elog_t));
n++;
if(*el == NULL)
@@ -1843,7 +1853,11 @@ int xl_mod_init()
int i;
s=(char*)pkg_malloc(HOSTNAME_MAX);
- if (!s) return -1;
+ if (!s)
+ {
+ PKG_MEM_ERROR;
+ return -1;
+ }
if (gethostname(s, HOSTNAME_MAX)<0) {
str_fullname.len = 0;
str_fullname.s = NULL;
@@ -1872,6 +1886,7 @@ int xl_mod_init()
}
s=(char*)pkg_malloc(HOSTNAME_MAX);
if (!s) {
+ PKG_MEM_ERROR;
pkg_free(str_fullname.s);
return -1;
}
@@ -1896,8 +1911,9 @@ int xl_mod_init()
memcpy(str_ipaddr.s, s, str_ipaddr.len);
str_ipaddr.s[str_ipaddr.len] = '\0';
} else {
+ pkg_free(s);
str_ipaddr.len=0;
- LOG(L_ERR, "ERROR: xl_mod_init: No memory left for str_ipaddr\n");
+ PKG_MEM_ERROR_FMT("for str_ipaddr\n");
}
} else if (strncmp(str_ipaddr.s, s, str_ipaddr.len)!=0) {
LOG(L_WARN, "WARNING: xl_mod_init: more IP %s not used\n", s);
diff --git a/src/modules/xprint/xprint.c b/src/modules/xprint/xprint.c
index 26ce25e550e..68f84271b3c 100644
--- a/src/modules/xprint/xprint.c
+++ b/src/modules/xprint/xprint.c
@@ -105,7 +105,7 @@ static int mod_init(void)
log_buf = (char*)pkg_malloc((buf_size+1)*sizeof(char));
if(log_buf==NULL)
{
- LOG(L_ERR, "mod_init: ERROR: no more memory\n");
+ PKG_MEM_ERROR;
return -1;
}
@@ -215,7 +215,7 @@ static int xplog_fixup(void** param, int param_no)
* needs to be created */
p = (fparam_t*)pkg_malloc(sizeof(fparam_t));
if (!p) {
- LOG(L_ERR, "xplog_fixup: not enough memory\n");
+ PKG_MEM_ERROR;
return -1;
}
p->v.i = level;