Fix some memory leaks and use-after-free (cppcheck)
This commit is contained in:
@ -278,6 +278,11 @@ int ANSTO_SctMakeDriveAdapter(SConnection *pCon, SicsInterp *pSics, void *object
|
|||||||
pSICSOBJ obj = NULL;
|
pSICSOBJ obj = NULL;
|
||||||
hdbCallback *cb;
|
hdbCallback *cb;
|
||||||
|
|
||||||
|
if(argc < 4){
|
||||||
|
SCWrite(pCon,"ERROR: not enough arguments for ANSTO_SctMakeDriveAdapter", eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
pNew = SCTDRIVMakeObject();
|
pNew = SCTDRIVMakeObject();
|
||||||
if(pNew == NULL){
|
if(pNew == NULL){
|
||||||
SCWrite(pCon,"ERROR: out of memory in ANSTO_SctMakeDriveAdapter",
|
SCWrite(pCon,"ERROR: out of memory in ANSTO_SctMakeDriveAdapter",
|
||||||
@ -285,11 +290,6 @@ int ANSTO_SctMakeDriveAdapter(SConnection *pCon, SicsInterp *pSics, void *object
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(argc < 4){
|
|
||||||
SCWrite(pCon,"ERROR: not enough arguments for ANSTO_SctMakeDriveAdapter", eError);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
pNew->write_node = FindHdbNode(NULL,argv[2], pCon);
|
pNew->write_node = FindHdbNode(NULL,argv[2], pCon);
|
||||||
pNew->read_node = FindHdbNode(NULL,argv[3], pCon);
|
pNew->read_node = FindHdbNode(NULL,argv[3], pCon);
|
||||||
obj = FindCommandData(pSics,argv[4], "SctController");
|
obj = FindCommandData(pSics,argv[4], "SctController");
|
||||||
|
@ -415,9 +415,12 @@ static int TclSetPar(void *self, SConnection * pCon, char *name,
|
|||||||
return OKOK;
|
return OKOK;
|
||||||
} else {
|
} else {
|
||||||
pDriv->errorCode = PARANOTFOUND;
|
pDriv->errorCode = PARANOTFOUND;
|
||||||
|
free(tclCommand);
|
||||||
|
free(tclCommandPara);;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(tclCommand);
|
||||||
return OKOK;
|
return OKOK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -909,8 +909,12 @@ pCodri MakeTcpDoChoDriver(char *tclArray, SConnection *pCon){
|
|||||||
allocate memory
|
allocate memory
|
||||||
*/
|
*/
|
||||||
pNew = (pCodri)malloc(sizeof(Codri));
|
pNew = (pCodri)malloc(sizeof(Codri));
|
||||||
|
if(!pNew){
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
self = (pTcpDoCho)malloc(sizeof(TcpDoCho));
|
self = (pTcpDoCho)malloc(sizeof(TcpDoCho));
|
||||||
if(!pNew || !self){
|
if(!self){
|
||||||
|
free(pNew);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(pNew,0,sizeof(Codri));
|
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);
|
SCWrite(pCon,"ERROR: number of choppers not in range 1 - 8",eError);
|
||||||
free(pNew);
|
free(pNew);
|
||||||
free(self);
|
free(self);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
self->numChoppers = port;
|
self->numChoppers = port;
|
||||||
|
|
||||||
|
@ -203,19 +203,21 @@ static int HttpProtInit(Ascon *a, SConnection *con,
|
|||||||
int argc, char *argv[]){
|
int argc, char *argv[]){
|
||||||
pHttpProt pHttp = NULL;
|
pHttpProt pHttp = NULL;
|
||||||
|
|
||||||
|
if(argc < 3){
|
||||||
|
SCWrite(con,"ERROR: too few arguments in HttpProtInit", eError);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
pHttp = calloc(sizeof(HttpProt), 1);
|
pHttp = calloc(sizeof(HttpProt), 1);
|
||||||
if(pHttp == NULL){
|
if(pHttp == NULL){
|
||||||
SCWrite(con,"ERROR: out of memory in HttpProtInit", eError);
|
SCWrite(con,"ERROR: out of memory in HttpProtInit", eError);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(argc < 3){
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
a->hostport = strdup(argv[1]);
|
a->hostport = strdup(argv[1]);
|
||||||
pHttp->binData = (pSICSData)FindCommandData(pServ->pSics,
|
pHttp->binData = (pSICSData)FindCommandData(pServ->pSics,
|
||||||
argv[2], "SICSData");
|
argv[2], "SICSData");
|
||||||
if(pHttp->binData == NULL){
|
if(pHttp->binData == NULL){
|
||||||
SCWrite(con,"ERROR: SICSData objct not found", eError);
|
SCWrite(con,"ERROR: SICSData object not found", eError);
|
||||||
|
free(pHttp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if(argc > 3){
|
if(argc > 3){
|
||||||
|
@ -286,12 +286,15 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
pNew = CreateEVDriver(argc,argv);
|
pNew = CreateEVDriver(argc,argv);
|
||||||
pSim = (pLAKESHORE340Driv)malloc(sizeof(LAKESHORE340Driv));
|
if (!pNew) {
|
||||||
memset(pSim,0,sizeof(LAKESHORE340Driv));
|
|
||||||
if(!pNew || !pSim)
|
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pSim = (pLAKESHORE340Driv)malloc(sizeof(LAKESHORE340Driv));
|
||||||
|
if (!pSim) {
|
||||||
|
free(pNew);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memset(pSim,0,sizeof(LAKESHORE340Driv));
|
||||||
pNew->pPrivate = pSim;
|
pNew->pPrivate = pSim;
|
||||||
pNew->KillPrivate = KillLAKESHORE340;
|
pNew->KillPrivate = KillLAKESHORE340;
|
||||||
|
|
||||||
|
@ -297,13 +297,16 @@
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pNew = CreateEVDriver(argc,argv);
|
|
||||||
pSim = (pWEST4100Driv)malloc(sizeof(WEST4100Driv));
|
pSim = (pWEST4100Driv)malloc(sizeof(WEST4100Driv));
|
||||||
memset(pSim,0,sizeof(WEST4100Driv));
|
if(!pSim) {
|
||||||
if(!pNew || !pSim)
|
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
pNew = CreateEVDriver(argc,argv);
|
||||||
|
if(!pNew) {
|
||||||
|
free(pSim);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memset(pSim,0,sizeof(WEST4100Driv));
|
||||||
pNew->pPrivate = pSim;
|
pNew->pPrivate = pSim;
|
||||||
pNew->KillPrivate = KillWEST4100;
|
pNew->KillPrivate = KillWEST4100;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user