Fix some memory leaks and use-after-free (cppcheck)

This commit is contained in:
Douglas Clowes
2014-03-03 17:18:52 +11:00
parent be347e813c
commit 9e65849964
6 changed files with 34 additions and 18 deletions

View File

@@ -909,8 +909,12 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
allocate memory
*/
pNew = (pCodri)malloc(sizeof(Codri));
if(!pNew){
return NULL;
}
self = (pTcpDoCho)malloc(sizeof(TcpDoCho));
if(!pNew || !self){
if(!self){
free(pNew);
return NULL;
}
memset(pNew,0,sizeof(Codri));
@@ -952,6 +956,7 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
SCWrite(pCon,"ERROR: number of choppers not in range 1 - 8",eError);
free(pNew);
free(self);
return NULL;
}
self->numChoppers = port;

View File

@@ -203,19 +203,21 @@ static int HttpProtInit(Ascon *a, SConnection *con,
int argc, char *argv[]){
pHttpProt pHttp = NULL;
if(argc < 3){
SCWrite(con,"ERROR: too few arguments in HttpProtInit", eError);
return 0;
}
pHttp = calloc(sizeof(HttpProt), 1);
if(pHttp == NULL){
SCWrite(con,"ERROR: out of memory in HttpProtInit", eError);
return 0;
}
if(argc < 3){
return 0;
}
a->hostport = strdup(argv[1]);
pHttp->binData = (pSICSData)FindCommandData(pServ->pSics,
argv[2], "SICSData");
if(pHttp->binData == NULL){
SCWrite(con,"ERROR: SICSData objct not found", eError);
SCWrite(con,"ERROR: SICSData object not found", eError);
free(pHttp);
return 0;
}
if(argc > 3){