- replaced all mallocs/frees w/ pkg_malloc/pkg_free
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 19 Mar 2003 18:41:58 +0000 (18:41 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Wed, 19 Mar 2003 18:41:58 +0000 (18:41 +0000)
- minor lock_dealloc warning fixes

17 files changed:
action.c
cfg.lex
cfg.y
fifo_server.c
flags.c
forward.c
ip_addr.c
lock_alloc.h
main.c
name_alias.h
proxy.c
route.c
route_struct.c
script_cb.c
sr_module.c
timer.c
udp_server.c

index 5c6f0d1..4730786 100644 (file)
--- a/action.c
+++ b/action.c
@@ -30,6 +30,7 @@
  * 2003-01-29  removed scratchpad (jiri)
  * 2003-03-19  fixed set* len calculation bug & simplified a little the code
  *              (should be a little faster now) (andrei)
+ *             replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -142,7 +143,7 @@ int do_action(struct action* a, struct sip_msg* msg)
                                ret=forward_request(msg, p, proto);
                                /*free_uri(&uri); -- no longer needed, in sip_msg*/
                                free_proxy(p); /* frees only p content, not p itself */
-                               free(p);
+                               pkg_free(p);
                                if (ret>=0) ret=1;
                        }else if ((a->p1_type==PROXY_ST) && (a->p2_type==NUMBER_ST)){
                                ret=forward_request(msg,(struct proxy_l*)a->p1.data, proto);
@@ -161,7 +162,8 @@ int do_action(struct action* a, struct sip_msg* msg)
                                ret=E_BUG;
                                break;
                        }
-                       to=(union sockaddr_union*) malloc(sizeof(union sockaddr_union));
+                       to=(union sockaddr_union*)
+                                       pkg_malloc(sizeof(union sockaddr_union));
                        if (to==0){
                                LOG(L_ERR, "ERROR: do_action: "
                                                        "memory allocation failure\n");
@@ -199,7 +201,7 @@ int do_action(struct action* a, struct sip_msg* msg)
                                }
 #endif
                        }
-                       free(to);
+                       pkg_free(to);
                        if (ret<0){
                                p->errors++;
                                p->ok=0;
diff --git a/cfg.lex b/cfg.lex
index 601702f..c103b1c 100644 (file)
--- a/cfg.lex
+++ b/cfg.lex
@@ -28,8 +28,9 @@
  *
  * History:
  * -------
- * 2001-01-29 src_port added (jiri)
- * 2001-01-23 mhomed added (jiri)
+ *  2003-01-29  src_port added (jiri)
+ *  2003-01-23  mhomed added (jiri)
+ *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
        #include "cfg.tab.h"
        #include "dprint.h"
        #include "globals.h"
+       #include "mem/mem.h"
        #include <string.h>
        #include <stdlib.h>
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
        /* states */
        #define INITIAL_S               0
@@ -330,7 +329,7 @@ EAT_ABLE    [\ \t\b\r]
                                                                                case STRING_S: 
                                                                                        LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF in"
                                                                                                                " unclosed string\n");
-                                                                                       if (tstr) {free(tstr); tstr=0;}
+                                                                                       if (tstr) {pkg_free(tstr);tstr=0;}
                                                                                        break;
                                                                                case COMMENT_S:
                                                                                        LOG(L_CRIT, "ERROR: cfg. parser: unexpected EOF:"
@@ -356,12 +355,12 @@ static char* addstr(char * src, char ** dest)
        }else{
                len1=strlen(*dest);
                len2=strlen(src);
-               tmp=malloc(len1+len2+1);
+               tmp=pkg_malloc(len1+len2+1);
                if (tmp==0) goto error;
                memcpy(tmp, *dest, len1);
                memcpy(tmp+len1, src, len2);
                tmp[len1+len2]=0;
-               free(*dest);
+               pkg_free(*dest);
                *dest=tmp;
        }
        return *dest;
diff --git a/cfg.y b/cfg.y
index 7843653..2f8822d 100644 (file)
--- a/cfg.y
+++ b/cfg.y
@@ -28,8 +28,9 @@
  *
  * History:
  * ---------
- * 2003-01-29 src_port added (jiri)
- * 2003-01-23 mhomed added (jiri)
+ * 2003-01-29  src_port added (jiri)
+ * 2003-01-23  mhomed added (jiri)
+ * 2003-03-19  replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -222,7 +223,7 @@ listen_id:  ip                      {       tmp=ip_addr2a($1);
                                                                                "addresss.\n");
                                                                $$=0;
                                                        }else{
-                                                               $$=malloc(strlen(tmp)+1);
+                                                               $$=pkg_malloc(strlen(tmp)+1);
                                                                if ($$==0){
                                                                        LOG(L_CRIT, "ERROR: cfg. parser: out of "
                                                                                        "memory.\n");
@@ -231,7 +232,7 @@ listen_id:  ip                      {       tmp=ip_addr2a($1);
                                                                }
                                                        }
                                                }
-                |      ID                      {       $$=malloc(strlen($1)+1);
+                |      ID                      {       $$=pkg_malloc(strlen($1)+1);
                                                        if ($$==0){
                                                                        LOG(L_CRIT, "ERROR: cfg. parser: out of "
                                                                                        "memory.\n");
@@ -239,7 +240,7 @@ listen_id:  ip                      {       tmp=ip_addr2a($1);
                                                                        strncpy($$, $1, strlen($1)+1);
                                                        }
                                                }
-                |      STRING                  {       $$=malloc(strlen($1)+1);
+                |      STRING                  {       $$=pkg_malloc(strlen($1)+1);
                                                        if ($$==0){
                                                                        LOG(L_CRIT, "ERROR: cfg. parser: out of "
                                                                                        "memory.\n");
@@ -247,7 +248,7 @@ listen_id:  ip                      {       tmp=ip_addr2a($1);
                                                                        strncpy($$, $1, strlen($1)+1);
                                                        }
                                                }
-                |      host            {       $$=malloc(strlen($1)+1);
+                |      host            {       $$=pkg_malloc(strlen($1)+1);
                                                        if ($$==0){
                                                                        LOG(L_CRIT, "ERROR: cfg. parser: out of "
                                                                                        "memory.\n");
@@ -257,7 +258,7 @@ listen_id:  ip                      {       tmp=ip_addr2a($1);
                                                }
        ;
 
-id_lst:          listen_id     {       $$=malloc(sizeof(struct id_list));
+id_lst:          listen_id     {       $$=pkg_malloc(sizeof(struct id_list));
                                                if ($$==0){
                                                        LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
                                                }else{
@@ -266,7 +267,7 @@ id_lst:       listen_id     {       $$=malloc(sizeof(struct id_list));
                                                }
                                        }
                | listen_id id_lst      {
-                                               $$=malloc(sizeof(struct id_list));
+                                               $$=pkg_malloc(sizeof(struct id_list));
                                                if ($$==0){
                                                        LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
                                                }else{
@@ -328,8 +329,8 @@ assign_stm: DEBUG EQUAL NUMBER { debug=$3; }
                | LISTEN EQUAL id_lst {
                                                        for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
                                                                if (sock_no < MAX_LISTEN){
-                                                                       sock_info[sock_no].name.s=
-                                                                               (char*)malloc(strlen(lst_tmp->s)+1);
+                                                                       sock_info[sock_no].name.s=(char*)
+                                                                                       pkg_malloc(strlen(lst_tmp->s)+1);
                                                                        if (sock_info[sock_no].name.s==0){
                                                                                LOG(L_CRIT, "ERROR: cfg. parser:"
                                                                                                        " out of memory.\n");
@@ -386,7 +387,8 @@ ip:          ipv4  { $$=$1; }
                ;
 
 ipv4:  NUMBER DOT NUMBER DOT NUMBER DOT NUMBER { 
-                                                                                       $$=malloc(sizeof(struct ip_addr));
+                                                                                       $$=pkg_malloc(
+                                                                                                       sizeof(struct ip_addr));
                                                                                        if ($$==0){
                                                                                                LOG(L_CRIT, "ERROR: cfg. "
                                                                                                        "parser: out of memory.\n"
@@ -419,7 +421,7 @@ ipv4:       NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
        ;
 
 ipv6:  IPV6ADDR {
-                                       $$=malloc(sizeof(struct ip_addr));
+                                       $$=pkg_malloc(sizeof(struct ip_addr));
                                        if ($$==0){
                                                LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
                                        }else{
@@ -611,7 +613,7 @@ ipnet:      ip SLASH ip     { $$=mk_net($1, $3); }
        ;
 
 host:  ID                              { $$=$1; }
-       | host DOT ID           { $$=(char*)malloc(strlen($1)+1+strlen($3)+1);
+       | host DOT ID           { $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
                                                  if ($$==0){
                                                        LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
                                                                                " failure while parsing host\n");
@@ -621,9 +623,9 @@ host:       ID                              { $$=$1; }
                                                        memcpy($$+strlen($1)+1, $3, strlen($3));
                                                        $$[strlen($1)+1+strlen($3)]=0;
                                                  }
-                                                 free($1); free($3);
+                                                 pkg_free($1); pkg_free($3);
                                                }
-       | host DOT error { $$=0; free($1); yyerror("invalid hostname"); }
+       | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
        ;
 
 
index 72da8ae..0ea2b90 100644 (file)
@@ -53,7 +53,8 @@
  *
  * History:
  * --------
- * 2003-01-29 new built-in fifo commands: arg and pwd (jiri)
+ *  2003-01-29  new built-in fifo commands: arg and pwd (jiri)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -117,7 +118,7 @@ int register_fifo_cmd(fifo_cmd f, char *cmd_name, void *param)
                LOG(L_ERR, "ERROR: register_fifo_cmd: attempt to register synonyms\n");
                return E_BUG;
        }
-       new_cmd=malloc(sizeof(struct fifo_command));
+       new_cmd=pkg_malloc(sizeof(struct fifo_command));
        if (new_cmd==0) {
                LOG(L_ERR, "ERROR: register_fifo_cmd: out of mem\n");
                return E_OUT_OF_MEM;
diff --git a/flags.c b/flags.c
index dbd6a63..a1e883c 100644 (file)
--- a/flags.c
+++ b/flags.c
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 #include <limits.h>
@@ -75,11 +80,12 @@ static int fixup_t_flag(void** param, int param_no)
        DBG("DEBUG: fixing flag: %s\n", (char *) (*param));
 
        if (param_no!=1) {
-               LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be fixed\n");
+               LOG(L_ERR, "ERROR: TM module: only parameter #1 for flags can be"
+                                       " fixed\n");
                return E_BUG;
        };
 
-       if ( !(code = malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
+       if ( !(code =pkg_malloc( sizeof( unsigned int) )) ) return E_OUT_OF_MEM;
 
        *code = 0;
        c = *param;
@@ -121,14 +127,14 @@ static int fixup_t_flag(void** param, int param_no)
        }
 
        /* free string */
-       free( *param );
+       pkg_free( *param );
        /* fix now */
        *param = code;
        
        return 0;
 
 error:
-       free( code );
+       pkg_free( code );
        return E_CFG;
 }
 
index a646b2f..f410bd3 100644 (file)
--- a/forward.c
+++ b/forward.c
  *
  * History:
  * -------
- * 2001-??-??  created by andrei
- * ????-??-??  lots of changes by a lot of people
- * 2003-01-23  support for determination of outbound interface added :
- *              get_out_socket (jiri)
- * 2003-01-24  reply to rport support added, contributed by
- *              Maxim Sobolev <sobomax@FreeBSD.org> and modified by andrei
- * 2003-02-11  removed calls to upd_send & tcp_send & replaced them with
- *              calls to msg_send (andrei)
+ *  2001-??-??  created by andrei
+ *  ????-??-??  lots of changes by a lot of people
+ *  2003-01-23  support for determination of outbound interface added :
+ *               get_out_socket (jiri)
+ *  2003-01-24  reply to rport support added, contributed by
+ *               Maxim Sobolev <sobomax@FreeBSD.org> and modified by andrei
+ *  2003-02-11  removed calls to upd_send & tcp_send & replaced them with
+ *               calls to msg_send (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -249,7 +250,7 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
        buf=0;
        id=0;
        
-       to=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
+       to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
        if (to==0){
                ser_error=E_OUT_OF_MEM;
                LOG(L_ERR, "ERROR: forward_request: out of memory\n");
@@ -325,12 +326,12 @@ int forward_request( struct sip_msg* msg, struct proxy_l * p, int proto)
        STATS_TX_REQUEST(  msg->first_line.u.request.method_value );
        
        pkg_free(buf);
-       free(to);
+       pkg_free(to);
        /* received_buf & line_buf will be freed in receive_msg by free_lump_list*/
        return 0;
 
 error1:
-       free(to);
+       pkg_free(to);
 error:
        if (buf) pkg_free(buf);
        return -1;
@@ -435,7 +436,7 @@ int forward_reply(struct sip_msg* msg)
                goto error;
        }
 
-       to=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
+       to=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
        if (to==0){
                LOG(L_ERR, "ERROR: forward_reply: out of memory\n");
                goto error;
@@ -474,11 +475,11 @@ int forward_reply(struct sip_msg* msg)
                        (unsigned short) msg->via2->port);
 
        pkg_free(new_buf);
-       free(to);
+       pkg_free(to);
 skip:
        return 0;
 error:
        if (new_buf) pkg_free(new_buf);
-       if (to) free(to);
+       if (to) pkg_free(to);
        return -1;
 }
index 06ae484..869ba8d 100644 (file)
--- a/ip_addr.c
+++ b/ip_addr.c
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free
+ */
 
 
 #include <stdlib.h>
@@ -34,6 +39,7 @@
 
 #include "ip_addr.h"
 #include "dprint.h"
+#include "mem/mem.h"
 
 
 struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask)
@@ -45,7 +51,7 @@ struct net* mk_net(struct ip_addr* ip, struct ip_addr* mask)
                                " (eg. ipv4/ipv6mask or ipv6/ipv4mask)\n");
                goto error;
        }
-       n=(struct net*)malloc(sizeof(struct net));
+       n=(struct net*)pkg_malloc(sizeof(struct net));
        if (n==0){ 
                LOG(L_CRIT, "ERROR: mk_net: memory allocation failure\n");
                goto error;
@@ -68,7 +74,7 @@ struct net* mk_net_bitlen(struct ip_addr* ip, unsigned int bitlen)
                LOG(L_CRIT, "ERROR: mk_net_bitlen: bad bitlen number %d\n", bitlen);
                goto error;
        }
-       n=(struct net*)malloc(sizeof(struct net));
+       n=(struct net*)pkg_malloc(sizeof(struct net));
        if (n==0){
                LOG(L_CRIT, "ERROR: mk_net_bitlen: memory allocation failure\n"); 
                goto error;
index 9b4abf3..317c556 100644 (file)
@@ -60,7 +60,7 @@ Implements: (see also locking.h)
 #if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
 /* simple locks*/
 #define lock_alloc() shm_malloc(sizeof(gen_lock_t))
-#define lock_dealloc(lock) shm_free(lock)
+#define lock_dealloc(lock) shm_free((void*)lock)
 /* lock sets */
 
 inline static lock_set_t* lock_set_alloc(int n)
@@ -82,7 +82,7 @@ inline static lock_set_t* lock_set_alloc(int n)
 
 /*simple locks*/
 #define lock_alloc() shm_malloc(sizeof(gen_lock_t))
-#define lock_dealloc(lock) shm_free(lock)
+#define lock_dealloc(lock) shm_free((void*)lock)
 /* lock sets */
 
 inline static lock_set_t* lock_set_alloc(int n)
diff --git a/main.c b/main.c
index 4efabfd..88331c8 100644 (file)
--- a/main.c
+++ b/main.c
@@ -26,8 +26,9 @@
  *
  * History:
  * -------
- * 2002-01-29 argc/argv globalized via my_{argc|argv} (jiri)
- * 2001-01-23 mhomed added (jiri)
+ * 2002-01-29  argc/argv globalized via my_{argc|argv} (jiri)
+ * 2003-01-23  mhomed added (jiri)
+ * 2003-03-19  replaced all malloc/frees w/ pkg_malloc/pkg_free (andrei)
  *
  */
 
@@ -947,7 +948,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
        ifc.ifc_req=0;
        for (size=10; ; size*=2){
                ifc.ifc_len=size*sizeof(struct ifreq);
-               ifc.ifc_req=(struct ifreq*) malloc(size*sizeof(struct ifreq));
+               ifc.ifc_req=(struct ifreq*) pkg_malloc(size*sizeof(struct ifreq));
                if (ifc.ifc_req==0){
                        fprintf(stderr, "memory allocation failure\n");
                        goto error;
@@ -961,7 +962,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
                                                                                                                   len not changed*/
                lastlen=ifc.ifc_len;
                /* try a bigger array*/
-               free(ifc.ifc_req);
+               pkg_free(ifc.ifc_req);
        }
        
        last=(char*)ifc.ifc_req+ifc.ifc_len;
@@ -1008,7 +1009,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
                                        (struct sockaddr*)(p+(long)&((struct ifreq*)0)->ifr_addr));
                                if ((tmp=ip_addr2a(&addr))==0) goto error;
                                /* fill the strings*/
-                               sock_info[sock_no].name.s=(char*)malloc(strlen(tmp)+1);
+                               sock_info[sock_no].name.s=(char*)pkg_malloc(strlen(tmp)+1);
                                if(sock_info[sock_no].name.s==0){
                                        fprintf(stderr, "Out of memory.\n");
                                        goto error;
@@ -1036,11 +1037,11 @@ int add_interfaces(char* if_name, int family, unsigned short port)
                        ls_ifflags(ifr->ifr_name, family, options);
                        printf("\n");*/
        }
-       free(ifc.ifc_req); /*clean up*/
+       pkg_free(ifc.ifc_req); /*clean up*/
        close(s);
        return  ret;
 error:
-       if (ifc.ifc_req) free(ifc.ifc_req);
+       if (ifc.ifc_req) pkg_free(ifc.ifc_req);
        close(s);
        return -1;
 }
@@ -1159,7 +1160,7 @@ int main(int argc, char** argv)
                                        /* add a new addr. to our address list */
                                        if (sock_no < MAX_LISTEN){
                                                sock_info[sock_no].name.s=
-                                                                               (char*)malloc(strlen(optarg)+1);
+                                                                               (char*)pkg_malloc(strlen(optarg)+1);
                                                if (sock_info[sock_no].name.s==0){
                                                        fprintf(stderr, "Out of memory.\n");
                                                        goto error;
@@ -1377,7 +1378,8 @@ try_again:
                                fprintf(stderr, "cannot determine hostname, try -l address\n");
                                goto error;
                        }
-                       sock_info[sock_no].name.s=(char*)malloc(strlen(myname.nodename)+1);
+                       sock_info[sock_no].name.s=
+                                                               (char*)pkg_malloc(strlen(myname.nodename)+1);
                        if (sock_info[sock_no].name.s==0){
                                fprintf(stderr, "Out of memory.\n");
                                goto error;
@@ -1395,7 +1397,7 @@ try_again:
                if (add_interfaces(sock_info[r].name.s, AF_INET,
                                        sock_info[r].port_no)!=-1){
                        /* success => remove current entry (shift the entire array)*/
-                       free(sock_info[r].name.s);
+                       pkg_free(sock_info[r].name.s);
                        memmove(&sock_info[r], &sock_info[r+1], 
                                                (sock_no-r)*sizeof(struct socket_info));
                        sock_no--;
@@ -1427,7 +1429,7 @@ try_again:
                  not have  enough space */
                port_no_str_len=
                                (port_no_str_len<MAX_PORT_LEN)?port_no_str_len:MAX_PORT_LEN;
-               sock_info[r].port_no_str.s=(char*)malloc(strlen(port_no_str)+1);
+               sock_info[r].port_no_str.s=(char*)pkg_malloc(strlen(port_no_str)+1);
                if (sock_info[r].port_no_str.s==0){
                        fprintf(stderr, "Out of memory.\n");
                        goto error;
@@ -1449,8 +1451,8 @@ try_again:
                                LOG(L_ERR, "ERROR: main: add_alias failed\n");
                        }
                        /* change the oficial name */
-                       free(sock_info[r].name.s);
-                       sock_info[r].name.s=(char*)malloc(strlen(he->h_name)+1);
+                       pkg_free(sock_info[r].name.s);
+                       sock_info[r].name.s=(char*)pkg_malloc(strlen(he->h_name)+1);
                        if (sock_info[r].name.s==0){
                                fprintf(stderr, "Out of memory.\n");
                                goto error;
@@ -1466,7 +1468,7 @@ try_again:
                hostent2ip_addr(&sock_info[r].address, he, 0); /*convert to ip_addr 
                                                                                                                 format*/
                if ((tmp=ip_addr2a(&sock_info[r].address))==0) goto error;
-               sock_info[r].address_str.s=(char*)malloc(strlen(tmp)+1);
+               sock_info[r].address_str.s=(char*)pkg_malloc(strlen(tmp)+1);
                if (sock_info[r].address_str.s==0){
                        fprintf(stderr, "Out of memory.\n");
                        goto error;
@@ -1527,9 +1529,9 @@ try_again:
                                                                sock_info[t].port_no);
                                                
                                /* free space*/
-                               free(sock_info[t].name.s);
-                               free(sock_info[t].address_str.s);
-                               free(sock_info[t].port_no_str.s);
+                               pkg_free(sock_info[t].name.s);
+                               pkg_free(sock_info[t].address_str.s);
+                               pkg_free(sock_info[t].port_no_str.s);
                                /* shift the array*/
                                memmove(&sock_info[t], &sock_info[t+1], 
                                                        (sock_no-t)*sizeof(struct socket_info));
@@ -1575,7 +1577,7 @@ try_again:
 #ifdef SHM_MEM
        pt=shm_malloc(sizeof(struct process_table)*process_count());
 #else
-       pt=malloc(sizeof(struct process_table)*process_count());
+       pt=pkg_malloc(sizeof(struct process_table)*process_count());
 #endif
        if (pt==0){
                fprintf(stderr, "ERROR: out  of memory\n");
index aa90646..1363a0e 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/*
+ * History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 
 #include "str.h"
 #include "dprint.h"
+#include "mem/mem.h"
 
 
 
@@ -68,9 +74,9 @@ static inline int add_alias(char* name, int len, unsigned short port)
        
        if ((port) && grep_aliases(name,len, port)) return 0;
        a=0;
-       a=(struct host_alias*)malloc(sizeof(struct host_alias));
+       a=(struct host_alias*)pkg_malloc(sizeof(struct host_alias));
        if(a==0) goto error;
-       a->alias.s=(char*)malloc(len+1);
+       a->alias.s=(char*)pkg_malloc(len+1);
        if (a->alias.s==0) goto error;
        a->alias.len=len;
        memcpy(a->alias.s, name, len);
@@ -81,7 +87,7 @@ static inline int add_alias(char* name, int len, unsigned short port)
        return 1;
 error:
        LOG(L_ERR, "ERROR: add_alias: memory allocation error\n");
-       if (a) free(a);
+       if (a) pkg_free(a);
        return -1;
 }
 
diff --git a/proxy.c b/proxy.c
index 5da694b..98ea2ce 100644 (file)
--- a/proxy.c
+++ b/proxy.c
@@ -31,6 +31,7 @@
   * History:
   * -------
   *  2003-02-13  all *proxy fucntions are now proto aware (andrei)
+  *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
   */
 
 
@@ -39,6 +40,7 @@
 #include "proxy.h"
 #include "error.h"
 #include "dprint.h"
+#include "mem/mem.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -52,9 +54,6 @@
 #include "ip_addr.h"
 #include "globals.h"
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 struct proxy_l* proxies=0;
 
@@ -86,7 +85,7 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
        /* start copying the host entry.. */
        /* copy h_name */
        len=strlen(src->h_name)+1;
-       dst->h_name=(char*)malloc(sizeof(char) * len);
+       dst->h_name=(char*)pkg_malloc(sizeof(char) * len);
        if (dst->h_name) strncpy(dst->h_name,src->h_name, len);
        else{
                ser_error=ret=E_OUT_OF_MEM;
@@ -97,21 +96,21 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
        len=0;
        if (src->h_aliases)
                for (;src->h_aliases[len];len++);
-       dst->h_aliases=(char**)malloc(sizeof(char*)*(len+1));
+       dst->h_aliases=(char**)pkg_malloc(sizeof(char*)*(len+1));
        if (dst->h_aliases==0){
                ser_error=ret=E_OUT_OF_MEM;
-               free(dst->h_name);
+               pkg_free(dst->h_name);
                goto error;
        }
        memset((void*)dst->h_aliases, 0, sizeof(char*) * (len+1) );
        for (i=0;i<len;i++){
                len2=strlen(src->h_aliases[i])+1;
-               dst->h_aliases[i]=(char*)malloc(sizeof(char)*len2);
+               dst->h_aliases[i]=(char*)pkg_malloc(sizeof(char)*len2);
                if (dst->h_aliases==0){
                        ser_error=ret=E_OUT_OF_MEM;
-                       free(dst->h_name);
-                       for(r=0; r<i; r++)      free(dst->h_aliases[r]);
-                       free(dst->h_aliases);
+                       pkg_free(dst->h_name);
+                       for(r=0; r<i; r++)      pkg_free(dst->h_aliases[r]);
+                       pkg_free(dst->h_aliases);
                        goto error;
                }
                strncpy(dst->h_aliases[i], src->h_aliases[i], len2);
@@ -120,26 +119,26 @@ static int hostent_cpy(struct hostent *dst, struct hostent* src)
        len=0;
        if (src->h_addr_list)
                for (;src->h_addr_list[len];len++);
-       dst->h_addr_list=(char**)malloc(sizeof(char*)*(len+1));
+       dst->h_addr_list=(char**)pkg_malloc(sizeof(char*)*(len+1));
        if (dst->h_addr_list==0){
                ser_error=ret=E_OUT_OF_MEM;
-               free(dst->h_name);
-               for(r=0; dst->h_aliases[r]; r++)        free(dst->h_aliases[r]);
-               free(dst->h_aliases[r]);
-               free(dst->h_aliases);
+               pkg_free(dst->h_name);
+               for(r=0; dst->h_aliases[r]; r++)        pkg_free(dst->h_aliases[r]);
+               pkg_free(dst->h_aliases[r]);
+               pkg_free(dst->h_aliases);
                goto error;
        }
        memset((void*)dst->h_addr_list, 0, sizeof(char*) * (len+1) );
        for (i=0;i<len;i++){
-               dst->h_addr_list[i]=(char*)malloc(sizeof(char)*src->h_length);
+               dst->h_addr_list[i]=(char*)pkg_malloc(sizeof(char)*src->h_length);
                if (dst->h_addr_list[i]==0){
                        ser_error=ret=E_OUT_OF_MEM;
-                       free(dst->h_name);
-                       for(r=0; dst->h_aliases[r]; r++)        free(dst->h_aliases[r]);
-                       free(dst->h_aliases[r]);
-                       free(dst->h_aliases);
-                       for (r=0; r<i;r++) free(dst->h_addr_list[r]);
-                       free(dst->h_addr_list);
+                       pkg_free(dst->h_name);
+                       for(r=0; dst->h_aliases[r]; r++)        pkg_free(dst->h_aliases[r]);
+                       pkg_free(dst->h_aliases[r]);
+                       pkg_free(dst->h_aliases);
+                       for (r=0; r<i;r++) pkg_free(dst->h_addr_list[r]);
+                       pkg_free(dst->h_addr_list);
                        goto error;
                }
                memcpy(dst->h_addr_list[i], src->h_addr_list[i], src->h_length);
@@ -162,16 +161,16 @@ error:
 void free_hostent(struct hostent *dst)
 {
        int r;
-       if (dst->h_name) free(dst->h_name);
+       if (dst->h_name) pkg_free(dst->h_name);
        if (dst->h_aliases){
-               for(r=0; dst->h_aliases[r]; r++)        free(dst->h_aliases[r]);
-               free(dst->h_aliases[r]);
-               free(dst->h_aliases);
+               for(r=0; dst->h_aliases[r]; r++)        pkg_free(dst->h_aliases[r]);
+               pkg_free(dst->h_aliases[r]);
+               pkg_free(dst->h_aliases);
        }
        if (dst->h_addr_list){
-               for (r=0; dst->h_addr_list[r];r++) free(dst->h_addr_list[r]);
-               free(dst->h_addr_list[r]);
-               free(dst->h_addr_list);
+               for (r=0; dst->h_addr_list[r];r++) pkg_free(dst->h_addr_list[r]);
+               pkg_free(dst->h_addr_list[r]);
+               pkg_free(dst->h_addr_list);
        }
 }
 
@@ -204,7 +203,7 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
        struct proxy_l* p;
        struct hostent* he;
 
-       p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
+       p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
        if (p==0){
                ser_error=E_OUT_OF_MEM;
                LOG(L_CRIT, "ERROR: mk_proxy: memory allocation failure\n");
@@ -221,11 +220,11 @@ struct proxy_l* mk_proxy(str* name, unsigned short port, int proto)
                ser_error=E_BAD_ADDRESS;
                LOG(L_CRIT, "ERROR: mk_proxy: could not resolve hostname:"
                                        " \"%.*s\"\n", name->len, name->s);
-               free(p);
+               pkg_free(p);
                goto error;
        }
        if (hostent_cpy(&(p->host), he)!=0){
-               free(p);
+               pkg_free(p);
                goto error;
        }
        p->ok=1;
@@ -242,7 +241,7 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
 {
        struct proxy_l* p;
 
-       p=(struct proxy_l*) malloc(sizeof(struct proxy_l));
+       p=(struct proxy_l*) pkg_malloc(sizeof(struct proxy_l));
        if (p==0){
                LOG(L_CRIT, "ERROR: mk_proxy_from_ip: memory allocation failure\n");
                goto error;
@@ -253,12 +252,12 @@ struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
        p->proto=proto;
        p->host.h_addrtype=ip->af;
        p->host.h_length=ip->len;
-       p->host.h_addr_list=malloc(2*sizeof(char*));
+       p->host.h_addr_list=pkg_malloc(2*sizeof(char*));
        if (p->host.h_addr_list==0) goto error;
        p->host.h_addr_list[1]=0;
-       p->host.h_addr_list[0]=malloc(ip->len+1);
+       p->host.h_addr_list[0]=pkg_malloc(ip->len+1);
        if (p->host.h_addr_list[0]==0){
-               free(p->host.h_addr_list);
+               pkg_free(p->host.h_addr_list);
                goto error;
        }
 
diff --git a/route.c b/route.c
index 5347d6c..c60a46e 100644 (file)
--- a/route.c
+++ b/route.c
  *
  * History:
  * --------
- * 2003-02-28  scratchpad compatibility abandoned (jiri)
- * 2003-01-28  scratchpad removed, src_port introduced (jiri)
- * 2003-03-10  updated to the new module exports format (andrei)
+ *  2003-02-28  scratchpad compatibility abandoned (jiri)
+ *  2003-01-28  scratchpad removed, src_port introduced (jiri)
+ *  2003-03-10  updated to the new module exports format (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
  
 #include "ip_addr.h"
 #include "resolve.h"
 #include "parser/parse_uri.h"
+#include "mem/mem.h"
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 /* main routing script table  */
 struct action* rlist[RT_NO];
@@ -98,7 +97,7 @@ static int fix_expr(struct expr* exp)
        }else if (exp->type==ELEM_T){
                        if (exp->op==MATCH_OP){
                                if (exp->subtype==STRING_ST){
-                                       re=(regex_t*)malloc(sizeof(regex_t));
+                                       re=(regex_t*)pkg_malloc(sizeof(regex_t));
                                        if (re==0){
                                                LOG(L_CRIT, "ERROR: fix_expr: memory allocation"
                                                                " failure\n");
@@ -108,11 +107,11 @@ static int fix_expr(struct expr* exp)
                                                                REG_EXTENDED|REG_NOSUB|REG_ICASE) ){
                                                LOG(L_CRIT, "ERROR: fix_expr : bad re \"%s\"\n",
                                                                        (char*) exp->r.param);
-                                               free(re);
+                                               pkg_free(re);
                                                return E_BAD_RE;
                                        }
                                        /* replace the string with the re */
-                                       free(exp->r.param);
+                                       pkg_free(exp->r.param);
                                        exp->r.param=re;
                                        exp->subtype=RE_ST;
                                }else if (exp->subtype!=RE_ST){
index cadf0c3..42d645e 100644 (file)
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * 2003-01-29 src_port introduced (jiri)
+ */
+/* History:
+ * --------
+ *  2003-01-29  src_port introduced (jiri)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
 
 #include "dprint.h"
 #include "ip_addr.h"
+#include "mem/mem.h"
 
-#ifdef DEBUG_DMALLOC
-#include <dmalloc.h>
-#endif
 
 struct expr* mk_exp(int op, struct expr* left, struct expr* right)
 {
        struct expr * e;
-       e=(struct expr*)malloc(sizeof (struct expr));
+       e=(struct expr*)pkg_malloc(sizeof (struct expr));
        if (e==0) goto error;
        e->type=EXP_T;
        e->op=op;
@@ -63,7 +64,7 @@ error:
 struct expr* mk_elem(int op, int subtype, int operand, void* param)
 {
        struct expr * e;
-       e=(struct expr*)malloc(sizeof (struct expr));
+       e=(struct expr*)pkg_malloc(sizeof (struct expr));
        if (e==0) goto error;
        e->type=ELEM_T;
        e->op=op;
@@ -82,7 +83,7 @@ struct action* mk_action(int type, int p1_type, int p2_type,
                                                                                        void* p1, void* p2)
 {
        struct action* a;
-       a=(struct action*)malloc(sizeof(struct action));
+       a=(struct action*)pkg_malloc(sizeof(struct action));
        if (a==0) goto  error;
        memset(a,0,sizeof(struct action));
        a->type=type;
index 5057519..10f99f2 100644 (file)
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/* History:
+ * --------
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 #include <stdlib.h>
 #include "script_cb.h"
 #include "dprint.h"
 #include "error.h"
+#include "mem/mem.h"
 
 static struct script_cb *pre_cb=0;
 static struct script_cb *post_cb=0;
@@ -44,7 +49,7 @@ int register_script_cb( cb_function f, callback_t t, void *param )
 {
        struct script_cb *new_cb;
 
-       new_cb=malloc(sizeof(struct script_cb));
+       new_cb=pkg_malloc(sizeof(struct script_cb));
        if (new_cb==0) {
                LOG(L_ERR, "ERROR: register_script_cb: out of memory\n");
                return E_OUT_OF_MEM;
index ded9c15..311898a 100644 (file)
  * --------
  *  2003-03-10  switched to new module_exports format: updated find_export,
  *               find_export_param, find_module (andrei)
+ *  2003-03-19  replaced all mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
 #include "sr_module.h"
 #include "dprint.h"
 #include "error.h"
+#include "mem/mem.h"
 
 #include <dlfcn.h>
 #include <strings.h>
@@ -127,7 +129,7 @@ int register_module(struct module_exports* e, char* path, void* handle)
        ret=-1;
 
        /* add module to the list */
-       if ((mod=malloc(sizeof(struct sr_module)))==0){
+       if ((mod=pkg_malloc(sizeof(struct sr_module)))==0){
                LOG(L_ERR, "load_module: memory allocation failure\n");
                ret=E_OUT_OF_MEM;
                goto error;
diff --git a/timer.c b/timer.c
index ff53de0..9512fd9 100644 (file)
--- a/timer.c
+++ b/timer.c
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+/* History:
+ * --------
+ *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
+ */
 
 
 #include "timer.h"
@@ -54,7 +58,7 @@ int init_timer()
        /* in this case get_ticks won't work! */
        LOG(L_INFO, "WARNING: no shared memory support compiled in"
                                " get_ticks won't work\n");
-       jiffies=malloc(sizeof(int));
+       jiffies=pkg_malloc(sizeof(int));
 #endif
        if (jiffies==0){
                LOG(L_CRIT, "ERROR: init_timer: could not init jiffies\n");
@@ -72,7 +76,7 @@ void destroy_timer()
 #ifdef SHM_MEM
                shm_free(jiffies); jiffies=0;
 #else
-               free(jiffies); jiffies=0;
+               pkg_free(jiffies); jiffies=0;
 #endif
        }
 }
@@ -85,7 +89,7 @@ int register_timer(timer_function f, void* param, unsigned int interval)
 {
        struct sr_timer* t;
 
-       t=malloc(sizeof(struct sr_timer));
+       t=pkg_malloc(sizeof(struct sr_timer));
        if (t==0){
                LOG(L_ERR, "ERROR: register_timer: out of memory\n");
                goto error;
index 1e596ac..6c26002 100644 (file)
@@ -26,8 +26,9 @@
  *
  * History
  * --------
- * 2003-01-28 packet zero-termination moved to receive_msg (jiri)
- * 2003-02-10 undoed the above changes (andrei)
+ *  2003-01-28  packet zero-termination moved to receive_msg (jiri)
+ *  2003-02-10  undoed the above changes (andrei)
+ *  2003-03-19  replaced all the mallocs/frees w/ pkg_malloc/pkg_free (andrei)
  */
 
 
@@ -52,9 +53,6 @@
 #include "mem/mem.h"
 #include "ip_addr.h"
 
-#ifdef DEBUG_DMALLOC
-#include <mem/dmalloc.h>
-#endif
 
 #ifdef DBG_MSG_QA
 /* message quality assurance -- frequently, bugs in ser have
@@ -212,7 +210,7 @@ int udp_init(struct socket_info* sock_info)
 
        addr=&sock_info->su;
 /*
-       addr=(union sockaddr_union*)malloc(sizeof(union sockaddr_union));
+       addr=(union sockaddr_union*)pkg_malloc(sizeof(union sockaddr_union));
        if (addr==0){
                LOG(L_ERR, "ERROR: udp_init: out of memory\n");
                goto error;
@@ -263,11 +261,11 @@ int udp_init(struct socket_info* sock_info)
                goto error;
        }
 
-/*     free(addr);*/
+/*     pkg_free(addr);*/
        return 0;
 
 error:
-/*     if (addr) free(addr);*/
+/*     if (addr) pkg_free(addr);*/
        return -1;
 }
 
@@ -287,7 +285,7 @@ int udp_rcv_loop()
        struct receive_info ri;
 
 
-       from=(union sockaddr_union*) malloc(sizeof(union sockaddr_union));
+       from=(union sockaddr_union*) pkg_malloc(sizeof(union sockaddr_union));
        if (from==0){
                LOG(L_ERR, "ERROR: udp_rcv_loop: out of memory\n");
                goto error;
@@ -350,12 +348,12 @@ int udp_rcv_loop()
                
        }
        /*
-       if (from) free(from);
+       if (from) pkg_free(from);
        return 0;
        */
        
 error:
-       if (from) free(from);
+       if (from) pkg_free(from);
        return -1;
 }