Skip to content

Commit

Permalink
core: cleanup, remove local_malloc/local_free #define in core
Browse files Browse the repository at this point in the history
- remove the unused local_malloc and local_free #define in the core
- they were introduced in 2002 and not touched in the repository since this time
- they pointed to pkg_malloc and pkg_free
  • Loading branch information
henningw committed Dec 23, 2018
1 parent e3ecad3 commit 5ba65fc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 45 deletions.
26 changes: 10 additions & 16 deletions src/core/io_wait.c
Expand Up @@ -43,12 +43,6 @@

#include "mem/mem.h"

#ifndef local_malloc
#define local_malloc pkg_malloc
#endif
#ifndef local_free
#define local_free pkg_free
#endif

char* poll_support="poll"
#ifdef HAVE_EPOLL
Expand Down Expand Up @@ -472,7 +466,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
h->poll_method=poll_method;

/* common stuff, everybody has fd_hash */
h->fd_hash=local_malloc(sizeof(*(h->fd_hash))*h->max_fd_no);
h->fd_hash=pkg_malloc(sizeof(*(h->fd_hash))*h->max_fd_no);
if (h->fd_hash==0){
PKG_MEM_CRITICAL;
goto error;
Expand All @@ -490,7 +484,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
#ifdef HAVE_DEVPOLL
case POLL_DEVPOLL:
#endif
h->fd_array=local_malloc(sizeof(*(h->fd_array))*h->max_fd_no);
h->fd_array=pkg_malloc(sizeof(*(h->fd_array))*h->max_fd_no);
if (h->fd_array==0){
PKG_MEM_CRITICAL;
goto error;
Expand Down Expand Up @@ -519,7 +513,7 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
#ifdef HAVE_EPOLL
case POLL_EPOLL_LT:
case POLL_EPOLL_ET:
h->ep_array=local_malloc(sizeof(*(h->ep_array))*h->max_fd_no);
h->ep_array=pkg_malloc(sizeof(*(h->ep_array))*h->max_fd_no);
if (h->ep_array==0){
PKG_MEM_CRITICAL;
goto error;
Expand All @@ -542,12 +536,12 @@ int init_io_wait(io_wait_h* h, int max_fd, enum poll_types poll_method)
decrease the array size.
*/
h->kq_array_size=2 * h->max_fd_no + h->kq_changes_size;
h->kq_array=local_malloc(sizeof(*(h->kq_array))*h->kq_array_size);
h->kq_array=pkg_malloc(sizeof(*(h->kq_array))*h->kq_array_size);
if (h->kq_array==0){
PKG_MEM_CRITICAL;
goto error;
}
h->kq_changes=local_malloc(sizeof(*(h->kq_changes))*
h->kq_changes=pkg_malloc(sizeof(*(h->kq_changes))*
h->kq_changes_size);
if (h->kq_changes==0){
PKG_MEM_CRITICAL;
Expand Down Expand Up @@ -585,7 +579,7 @@ void destroy_io_wait(io_wait_h* h)
case POLL_EPOLL_ET:
destroy_epoll(h);
if (h->ep_array){
local_free(h->ep_array);
pkg_free(h->ep_array);
h->ep_array=0;
}
break;
Expand All @@ -594,11 +588,11 @@ void destroy_io_wait(io_wait_h* h)
case POLL_KQUEUE:
destroy_kqueue(h);
if (h->kq_array){
local_free(h->kq_array);
pkg_free(h->kq_array);
h->kq_array=0;
}
if (h->kq_changes){
local_free(h->kq_changes);
pkg_free(h->kq_changes);
h->kq_changes=0;
}
break;
Expand All @@ -617,11 +611,11 @@ void destroy_io_wait(io_wait_h* h)
;
}
if (h->fd_array){
local_free(h->fd_array);
pkg_free(h->fd_array);
h->fd_array=0;
}
if (h->fd_hash){
local_free(h->fd_hash);
pkg_free(h->fd_hash);
h->fd_hash=0;
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/io_wait.h
Expand Up @@ -33,9 +33,6 @@
* to int). 0 has a special not set/not init. meaning
* (a lot of sanity checks and the sigio_rt code are based on
* this assumption)
* local_malloc (defaults to pkg_malloc)
* local_free (defaults to pkg_free)
*
*/

#ifndef _io_wait_h
Expand Down
43 changes: 20 additions & 23 deletions src/core/resolve.c
Expand Up @@ -54,9 +54,6 @@ counter_def_t dns_cnt_defs[] = {
{0, 0, 0, 0, 0, 0 }
};

/* mallocs for local stuff */
#define local_malloc pkg_malloc
#define local_free pkg_free

#ifdef USE_NAPTR
static int naptr_proto_pref[PROTO_LAST+1];
Expand Down Expand Up @@ -305,7 +302,7 @@ struct srv_rdata* dns_srv_parser( unsigned char* msg, unsigned char* end,
if (len>255)
goto error;
/* alloc enought space for the struct + null terminated name */
srv=local_malloc(sizeof(struct srv_rdata)-1+len+1);
srv=pkg_malloc(sizeof(struct srv_rdata)-1+len+1);
if (srv==0){
PKG_MEM_ERROR;
goto error;
Expand All @@ -319,7 +316,7 @@ struct srv_rdata* dns_srv_parser( unsigned char* msg, unsigned char* end,

return srv;
error:
if (srv) local_free(srv);
if (srv) pkg_free(srv);
return 0;
}

Expand Down Expand Up @@ -391,7 +388,7 @@ struct naptr_rdata* dns_naptr_parser( unsigned char* msg, unsigned char* end,
len=strlen(repl);
if (len>255)
goto error;
naptr=local_malloc(sizeof(struct naptr_rdata)+flags_len+services_len+
naptr=pkg_malloc(sizeof(struct naptr_rdata)+flags_len+services_len+
regexp_len+len+1-1);
if (naptr == 0){
PKG_MEM_ERROR;
Expand All @@ -416,7 +413,7 @@ struct naptr_rdata* dns_naptr_parser( unsigned char* msg, unsigned char* end,

return naptr;
error:
if (naptr) local_free(naptr);
if (naptr) pkg_free(naptr);
return 0;
}

Expand All @@ -437,7 +434,7 @@ struct cname_rdata* dns_cname_parser( unsigned char* msg, unsigned char* end,
if (len>255)
goto error;
/* alloc sizeof struct + space for the null terminated name */
cname=local_malloc(sizeof(struct cname_rdata)-1+len+1);
cname=pkg_malloc(sizeof(struct cname_rdata)-1+len+1);
if(cname==0){
PKG_MEM_ERROR;
goto error;
Expand All @@ -447,7 +444,7 @@ struct cname_rdata* dns_cname_parser( unsigned char* msg, unsigned char* end,
cname->name[cname->name_len]=0;
return cname;
error:
if (cname) local_free(cname);
if (cname) pkg_free(cname);
return 0;
}

Expand All @@ -461,7 +458,7 @@ struct a_rdata* dns_a_parser(unsigned char* rdata, unsigned char* eor)
struct a_rdata* a;

if (rdata+4>eor) goto error;
a=(struct a_rdata*)local_malloc(sizeof(struct a_rdata));
a=(struct a_rdata*)pkg_malloc(sizeof(struct a_rdata));
if (a==0){
PKG_MEM_ERROR;
goto error;
Expand All @@ -481,7 +478,7 @@ struct aaaa_rdata* dns_aaaa_parser(unsigned char* rdata, unsigned char* eor)
struct aaaa_rdata* aaaa;

if (rdata+16>eor) goto error;
aaaa=(struct aaaa_rdata*)local_malloc(sizeof(struct aaaa_rdata));
aaaa=(struct aaaa_rdata*)pkg_malloc(sizeof(struct aaaa_rdata));
if (aaaa==0){
PKG_MEM_ERROR;
goto error;
Expand Down Expand Up @@ -531,7 +528,7 @@ static struct txt_rdata* dns_txt_parser(unsigned char* msg, unsigned char* end,
}while(p<end);
/* alloc sizeof struct + space for the dns_cstr array + space for
the strings */
txt=local_malloc(sizeof(struct txt_rdata) +(n-1)*sizeof(struct dns_cstr)+
txt=pkg_malloc(sizeof(struct txt_rdata) +(n-1)*sizeof(struct dns_cstr)+
str_size);
if(unlikely(txt==0)){
PKG_MEM_ERROR;
Expand All @@ -555,7 +552,7 @@ static struct txt_rdata* dns_txt_parser(unsigned char* msg, unsigned char* end,
}
return txt;
error:
if (txt) local_free(txt);
if (txt) pkg_free(txt);
return 0;
}

Expand Down Expand Up @@ -602,7 +599,7 @@ static struct ebl_rdata* dns_ebl_parser(unsigned char* msg, unsigned char* end,
goto error;
apex_len=strlen(apex);
/* alloc sizeof struct + space for the 2 null-terminated strings */
ebl=local_malloc(sizeof(struct ebl_rdata)-1+sep_len+1+apex_len+1);
ebl=pkg_malloc(sizeof(struct ebl_rdata)-1+sep_len+1+apex_len+1);
if (ebl==0){
PKG_MEM_ERROR;
goto error;
Expand All @@ -619,7 +616,7 @@ static struct ebl_rdata* dns_ebl_parser(unsigned char* msg, unsigned char* end,

return ebl;
error:
if (ebl) local_free(ebl);
if (ebl) pkg_free(ebl);
return 0;
}

Expand All @@ -640,7 +637,7 @@ struct ptr_rdata* dns_ptr_parser( unsigned char* msg, unsigned char* end,
if (len>255)
goto error;
/* alloc sizeof struct + space for the null terminated name */
pname=local_malloc(sizeof(struct ptr_rdata)-1+len+1);
pname=pkg_malloc(sizeof(struct ptr_rdata)-1+len+1);
if(pname==0){
PKG_MEM_ERROR;
goto error;
Expand All @@ -650,7 +647,7 @@ struct ptr_rdata* dns_ptr_parser( unsigned char* msg, unsigned char* end,
pname->ptrdname[pname->ptrdname_len]=0;
return pname;
error:
if (pname) local_free(pname);
if (pname) pkg_free(pname);
return 0;
}

Expand All @@ -665,8 +662,8 @@ void free_rdata_list(struct rdata* head)
while (l != 0) {
next_l = l->next;
/* free the parsed rdata*/
if (l->rdata) local_free(l->rdata);
local_free(l);
if (l->rdata) pkg_free(l->rdata);
pkg_free(l);
l = next_l;
}
}
Expand Down Expand Up @@ -833,7 +830,7 @@ struct rdata* get_record(char* name, int type, int flags)
}
/* expand the "type" record (rdata)*/

rd=(struct rdata*) local_malloc(sizeof(struct rdata)+rec_name_len+
rd=(struct rdata*) pkg_malloc(sizeof(struct rdata)+rec_name_len+
1-1);
if (rd==0){
PKG_MEM_ERROR;
Expand Down Expand Up @@ -972,7 +969,7 @@ struct rdata* get_record(char* name, int type, int flags)
* (queried) to long name (answered)
*/
if ((search_list_used==1)&&(fullname_rd!=0)) {
rd=(struct rdata*) local_malloc(sizeof(struct rdata)+name_len+1-1);
rd=(struct rdata*) pkg_malloc(sizeof(struct rdata)+name_len+1-1);
if (unlikely(rd==0)){
PKG_MEM_ERROR;
goto error;
Expand All @@ -985,7 +982,7 @@ struct rdata* get_record(char* name, int type, int flags)
rd->name[name_len]=0;
rd->name_len=name_len;
/* alloc sizeof struct + space for the null terminated name */
rd->rdata=(void*)local_malloc(sizeof(struct cname_rdata)-1+
rd->rdata=(void*)pkg_malloc(sizeof(struct cname_rdata)-1+
head->name_len+1);
if(unlikely(rd->rdata==0)){
PKG_MEM_ERROR;
Expand All @@ -1009,7 +1006,7 @@ struct rdata* get_record(char* name, int type, int flags)
name, type,
p, end, rtype, class, ttl, rdlength);
error_rd:
if (rd) local_free(rd); /* rd->rdata=0 & rd is not linked yet into
if (rd) pkg_free(rd); /* rd->rdata=0 & rd is not linked yet into
the list */
error:
LM_ERR("get_record\n");
Expand Down
3 changes: 0 additions & 3 deletions src/core/tcp_main.c
Expand Up @@ -100,9 +100,6 @@
#include "ut.h"
#include "cfg/cfg_struct.h"

#define local_malloc pkg_malloc
#define local_free pkg_free

#include <fcntl.h> /* must be included after io_wait.h if SIGIO_RT is used */


Expand Down

0 comments on commit 5ba65fc

Please sign in to comment.