From e593f6a22fbebe7a06dd4b08b378ab5d12e7d8ad Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 6 Jun 2012 10:22:39 +0200 Subject: fixing memleak in recent group resolve patch also added some error checking --- runtime/cfsysline.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'runtime/cfsysline.c') diff --git a/runtime/cfsysline.c b/runtime/cfsysline.c index a33810ed..08ca65ca 100644 --- a/runtime/cfsysline.c +++ b/runtime/cfsysline.c @@ -342,8 +342,8 @@ static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p struct group gBuf; DEFiRet; uchar szName[256]; - long bufSize = 2048; - char * stringBuf = malloc(bufSize); + int bufSize = 2048; + char * stringBuf = NULL; assert(pp != NULL); assert(*pp != NULL); @@ -353,13 +353,15 @@ static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p ABORT_FINALIZE(RS_RET_NOT_FOUND); } + + CHKmalloc(stringBuf = malloc(bufSize)); while(pgBuf == NULL) { errno = 0; getgrnam_r((char*)szName, &gBuf, stringBuf, bufSize, &pgBuf); if((pgBuf == NULL) && (errno == ERANGE)) { /* Increase bufsize and try again.*/ bufSize *= 2; - stringBuf = realloc(stringBuf, bufSize); + CHKmalloc(stringBuf = realloc(stringBuf, bufSize)); } } @@ -380,6 +382,7 @@ static rsRetVal doGetGID(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p skipWhiteSpace(pp); /* skip over any whitespace */ finalize_it: + free(stringBuf); RETiRet; } -- cgit v1.2.3