diff options
author | Simo Sorce <idra@samba.org> | 2001-08-12 17:30:01 +0000 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2001-08-12 17:30:01 +0000 |
commit | 2e783a47076bd0994b6ce86df7ec967bc1c2da63 (patch) | |
tree | c6504d6e8396eef290fe499abb8586b758f1f3d4 /source3/param | |
parent | ddec8306586414cc02eca612777bb547cb8dbcae (diff) | |
download | samba-2e783a47076bd0994b6ce86df7ec967bc1c2da63.tar.gz samba-2e783a47076bd0994b6ce86df7ec967bc1c2da63.tar.bz2 samba-2e783a47076bd0994b6ce86df7ec967bc1c2da63.zip |
this is a big global fix for the ptr = Realloc(ptr, size) bug.
many possible mem leaks, and segfaults fixed.
someone should port this fix to 2.2 also.
(This used to be commit fa8e55b8b465114ce209344965c1ca0333b84db9)
Diffstat (limited to 'source3/param')
-rw-r--r-- | source3/param/loadparm.c | 23 | ||||
-rw-r--r-- | source3/param/params.c | 27 |
2 files changed, 34 insertions, 16 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index cb7f9f35c3..b004265261 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -1782,16 +1782,25 @@ static int add_a_service(service * pservice, char *name) /* if not, then create one */ if (i == iNumServices) { - ServicePtrs = - (service **) Realloc(ServicePtrs, - sizeof(service *) * - num_to_alloc); - if (ServicePtrs) + service **tsp; + + tsp = (service **) Realloc(ServicePtrs, + sizeof(service *) * + num_to_alloc); + + if (!tsp) { + DEBUG(0,("add_a_service: failed to enlarge ServicePtrs!\n")); + return (-1); + } + else { + ServicePtrs = tsp; ServicePtrs[iNumServices] = (service *) malloc(sizeof(service)); - - if (!ServicePtrs || !ServicePtrs[iNumServices]) + } + if (!ServicePtrs[iNumServices]) { + DEBUG(0,("add_a_service: out of memory!\n")); return (-1); + } iNumServices++; } diff --git a/source3/param/params.c b/source3/param/params.c index 61baf9517c..9416965919 100644 --- a/source3/param/params.c +++ b/source3/param/params.c @@ -238,13 +238,16 @@ static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) ) /* Check that the buffer is big enough for the next character. */ if( i > (bSize - 2) ) { - bSize += BUFR_INC; - bufr = Realloc( bufr, bSize ); - if( NULL == bufr ) + char *tb; + + tb = Realloc( bufr, bSize +BUFR_INC ); + if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } + bufr = tb; + bSize += BUFR_INC; } /* Handle a single character. */ @@ -332,13 +335,16 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) if( i > (bSize - 2) ) /* Ensure there's space for next char. */ { - bSize += BUFR_INC; - bufr = Realloc( bufr, bSize ); - if( NULL == bufr ) + char *tb; + + tb = Realloc( bufr, bSize + BUFR_INC ); + if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } + bufr = tb; + bSize += BUFR_INC; } switch( c ) @@ -397,13 +403,16 @@ static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c ) if( i > (bSize - 2) ) /* Make sure there's enough room. */ { - bSize += BUFR_INC; - bufr = Realloc( bufr, bSize ); - if( NULL == bufr ) + char *tb; + + tb = Realloc( bufr, bSize + BUFR_INC ); + if( NULL == tb ) { DEBUG(0, ("%s Memory re-allocation failure.", func) ); return( False ); } + bufr = tb; + bSize += BUFR_INC; } switch( c ) |