Skip to content

Commit

Permalink
xprint: convert to memory logging helper, improve mem error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pantelisk98 authored and henningw committed Apr 21, 2023
1 parent b65c19f commit ad68787
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions src/modules/xprint/xp_lib.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/xprint/xprint.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ad68787

Please sign in to comment.