Re: another emi2 bugfix
Harrie Hazewinkel <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <2093803.1028633928@localhost> |
--On Tuesday, July 30, 2002 11:18 AM +0200 Harrie Hazewinkel <[email protected]> wrote: > --On Monday, July 22, 2002 1:34 PM +0300 Kaido Karner <[email protected]> > wrote: > >> re >> >> emi2 smsc connections by mistake increase received messages counter >> twice. >> >> patch is together with the previous fix in smsc_emi2.c >> >> >> diff -u gateway-1.2.0/gw/smsc_emi2.c gateway-patched/gw/smsc_emi2.c >> --- gateway-1.2.0/gw/smsc_emi2.c Fri Jun 28 14:09:54 2002 >> +++ gateway-patched/gw/smsc_emi2.c Mon Jul 22 13:29:15 2002 > [snip] >> @@ -1606,8 +1605,6 @@ >> privdata->deny_ip = deny_ip; >> >> if (privdata->rport > 0 && emi2_open_listening_socket(privdata) < 0) >> { - gw_free(privdata); >> - privdata = NULL; > > I think I would prefer to have these combined into a single function. > gw_free now maps onto the gw_native_free or gw_check_free with macros. > We could make the macros as such that they pass the pointer to the > address space containing the pointer and make the pointer even NULL. The patch below would combine a free(ptr) and a ptr=NULL into a single gw_free(ptr) statement. The extra vaiable is needed in case the variable is returned from a function. This should be wise to include too, I guess. Index: gwlib/gwmem.h =================================================================== RCS file: /home/cvs/gateway/gwlib/gwmem.h,v retrieving revision 1.21 diff -u -r1.21 gwmem.h --- gwlib/gwmem.h 17 Jun 2002 03:28:10 -0000 1.21 +++ gwlib/gwmem.h 6 Aug 2002 09:36:31 -0000 @@ -62,7 +62,7 @@ #define gw_check_leaks() #define gw_malloc(size) (gw_native_malloc(size)) #define gw_realloc(ptr, size) (gw_native_realloc(ptr, size)) -#define gw_free(ptr) (gw_native_free(ptr)) +#define gw_free(ptr) {void *p=ptr;gw_native_free(p);p=NULL;} #define gw_strdup(str) (gw_native_strdup(str)) #define gw_assert_allocated(ptr, file, line, function) #define gw_claim_area(ptr) (gw_native_noop(ptr)) @@ -90,7 +90,7 @@ #define gw_realloc(ptr, size) \ (gw_check_realloc(ptr, size, __FILE__, __LINE__, __func__)) #define gw_free(ptr) \ - (gw_check_free(ptr, __FILE__, __LINE__, __func__)) + {void *p=ptr;gw_check_free(p, __FILE__, __LINE__, __func__);p=NULL;} #define gw_strdup(str) \ (gw_check_strdup(str, __FILE__, __LINE__, __func__)) #define gw_assert_allocated(ptr, file, line, function) \ Although, I wanted to realise the above first by doing it in the final function, I realised that this would not be possible if the pointer is returned from a function. Harrie Internet Management Consulting mailto:[email protected] http ://www.mod-snmp.com/ ------------------------------------------------------------------- Author of MOD-SNMP, enabling SNMP management to the Apache server.