Re: another emi2 bugfix
Harrie Hazewinkel <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <2630101.1028644381@localhost> |
--On Tuesday, August 6, 2002 3:13 PM +0300 Oded Arbel <[email protected]> wrote: >> > >> >> +#define gw_free(ptr) {void *p=ptr;gw_native_free(p);p=NULL;} >> > >> > don't you mean : >> ># define gw_free(ptr) {void *p=ptr;gw_native_free(p);ptr=NULL;} >> > as p is freed from the stack anyway at the end of the macro block. the >> > same to the other change. >> >> NO, since 'ptr' can be directly returned from a function and that >> cannot be made NULL. However, I realise now also that this >> would not do the trick. It makes the new variable NULL, but not the >> pointer I wanted. >> >> Better drop it for now, and add explicits NULL assignments >> each time when needed. > > Why would you ever want to return a pointer after calling gw_free on it ? > after freeing a memory segment, the pointer to it must either be set to > NULL or discarded. > doing > gw_free(pointer); > return pointer; > make no sense what so ever, unless gw_free also assigns NULL to the > pointer. No, I did not mean that the pointer to be returned from gw_free(). I ment the pointer going INTO gw_free(). That pointer could be returned from a function. Then you do not have a pointer that can be made NULL, since it is returned as a value and not a reference to a value. This is where the pointer can be made NULL: void *ptr = gw_malloc(1); gw_free(ptr); ptr = NULL; This is where it cannot: gw_free(gw_malloc(1)); There is no explicit pointer. Hope this clarifies it, Harrie Internet Management Consulting mailto:[email protected] http ://www.mod-snmp.com/ ------------------------------------------------------------------- Author of MOD-SNMP, enabling SNMP management to the Apache server.