Skip to content

Commit

Permalink
Explicitly return NULL or 0 on M_ABORT error.
Browse files Browse the repository at this point in the history
This makes the work for static analyzing tools a lot easier that
don't understand that a M_ABORT means stop executing the program
and abort creating a crash on our way out.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent 9d0bf80 commit 06f1ded
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/lib/mem_pool.c
Expand Up @@ -111,7 +111,9 @@ POOLMEM *sm_get_pool_memory(const char *fname, int lineno, int pool)

if (pool > PM_MAX) {
Emsg2(M_ABORT, 0, _("MemPool index %d larger than max %d\n"), pool, PM_MAX);
return NULL;
}

P(mutex);
if (pool_ctl[pool].free_buf) {
buf = pool_ctl[pool].free_buf;
Expand All @@ -129,7 +131,9 @@ POOLMEM *sm_get_pool_memory(const char *fname, int lineno, int pool)
if ((buf = (struct abufhead *)sm_malloc(fname, lineno, pool_ctl[pool].size + HEAD_SIZE)) == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), pool_ctl[pool].size);
return NULL;
}

buf->ablen = pool_ctl[pool].size;
buf->pool = pool;
pool_ctl[pool].in_use++;
Expand All @@ -149,7 +153,9 @@ POOLMEM *sm_get_memory(const char *fname, int lineno, int32_t size)

if ((buf = (struct abufhead *)sm_malloc(fname, lineno, size + HEAD_SIZE)) == NULL) {
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
return NULL;
}

buf->ablen = size;
buf->pool = pool;
buf->next = NULL;
Expand All @@ -168,7 +174,9 @@ int32_t sm_sizeof_pool_memory(const char *fname, int lineno, POOLMEM *obuf)

if (obuf == NULL) {
Emsg0(M_ABORT, 0, _("obuf is NULL\n"));
return 0;
}

cp -= HEAD_SIZE;
return ((struct abufhead *)cp)->ablen;
}
Expand All @@ -187,7 +195,9 @@ POOLMEM *sm_realloc_pool_memory(const char *fname, int lineno, POOLMEM *obuf, in
if (buf == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
return NULL;
}

((struct abufhead *)buf)->ablen = size;
pool = ((struct abufhead *)buf)->pool;
if (size > pool_ctl[pool].max_allocated) {
Expand Down Expand Up @@ -258,7 +268,9 @@ POOLMEM *get_pool_memory(int pool)
if ((buf=malloc(pool_ctl[pool].size + HEAD_SIZE)) == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), pool_ctl[pool].size);
return NULL;
}

buf->ablen = pool_ctl[pool].size;
buf->pool = pool;
buf->next = NULL;
Expand All @@ -278,7 +290,9 @@ POOLMEM *get_memory(int32_t size)

if ((buf=malloc(size + HEAD_SIZE)) == NULL) {
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
return NULL;
}

buf->ablen = size;
buf->pool = pool;
buf->next = NULL;
Expand Down Expand Up @@ -313,7 +327,9 @@ POOLMEM *realloc_pool_memory(POOLMEM *obuf, int32_t size)
if (buf == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
return NULL;
}

((struct abufhead *)buf)->ablen = size;
pool = ((struct abufhead *)buf)->pool;
if (size > pool_ctl[pool].max_allocated) {
Expand Down Expand Up @@ -637,7 +653,9 @@ void POOL_MEM::realloc_pm(int32_t size)
if (buf == NULL) {
V(mutex);
Emsg1(M_ABORT, 0, _("Out of memory requesting %d bytes\n"), size);
return NULL;
}

Dmsg2(900, "Old buf=%p new buf=%p\n", cp, buf);
((struct abufhead *)buf)->ablen = size;
pool = ((struct abufhead *)buf)->pool;
Expand Down

0 comments on commit 06f1ded

Please sign in to comment.