- Introducted Arg2Tcl as a replacement for some calls to Arg2Text
- Fixed a memory leak
This commit is contained in:
67
macro.c
67
macro.c
@@ -174,14 +174,14 @@
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
pSics->lastUnknown[pSics->iStack] = strdup(comBuffer);
|
||||
if (pSics->lastUnknown[pSics->iStack]) free(pSics->lastUnknown[pSics->iStack]);
|
||||
pSics->lastUnknown[pSics->iStack] = strdup(comBuffer);
|
||||
|
||||
/* invoke */
|
||||
iMacro = SCinMacro(pCon);
|
||||
SCsetMacro(pCon,1);
|
||||
iRet = pCommand->OFunc(pCon,pSinter,pCommand->pData,margc, myarg);
|
||||
SCsetMacro(pCon,iMacro);
|
||||
|
||||
/*
|
||||
lastUnkown gets deeply stacked with each SICS command exec'd.
|
||||
This is not reflected in code. However, lastUnknown has already
|
||||
@@ -844,6 +844,7 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pBueffel[1024];
|
||||
char *pCommand;
|
||||
pPubTcl self = NULL;
|
||||
int iRet, length;
|
||||
char *pPtr;
|
||||
@@ -864,45 +865,32 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp,
|
||||
}
|
||||
|
||||
/* make a string */
|
||||
Arg2Text(argc,argv,pBueffel,1023);
|
||||
|
||||
|
||||
iRet = Tcl_Eval(pTcl,pBueffel);
|
||||
pCommand = Arg2Tcl(argc,argv,pBueffel,sizeof(pBueffel));
|
||||
if (!pCommand) {
|
||||
SCWrite(pCon, "ERROR: no more memory", eError);
|
||||
return 0;
|
||||
}
|
||||
iRet = Tcl_Eval(pTcl,pCommand);
|
||||
if (pCommand != pBueffel) free(pCommand);
|
||||
if(iRet == TCL_OK)
|
||||
{ length = strlen(pTcl->result);
|
||||
if(length < 1024){
|
||||
strncpy(pBueffel,pTcl->result,1023);
|
||||
SCWrite(pCon,pBueffel,eStatus);
|
||||
} else {
|
||||
length += 10;
|
||||
pPtr = (char *)malloc(length*sizeof(char));
|
||||
if(pPtr == NULL){
|
||||
SCWrite(pCon,
|
||||
"ERROR: out of memory in TclAction",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pPtr,0,length*sizeof(char));
|
||||
strncpy(pPtr,pTcl->result,length-1);
|
||||
SCWrite(pCon,pPtr,eStatus);
|
||||
free(pPtr);
|
||||
}
|
||||
{
|
||||
/* we do not now why, but at some time it was found that
|
||||
we need a copy, and can not use pTcl->result directly
|
||||
|
||||
SCWrite(pCon,pTcl->result,eStatus);
|
||||
|
||||
let us use SCPrintf, which maked always a copy
|
||||
*/
|
||||
SCPrintf(pCon, eStatus, "%s", pTcl->result);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Tcl_GetVar(pTcl,SICSERROR,TCL_GLOBAL_ONLY) == NULL)
|
||||
{
|
||||
pPtr = strdup(pTcl->result);
|
||||
SCWrite(pCon,pPtr,eError);
|
||||
free(pPtr);
|
||||
}
|
||||
else
|
||||
if(Tcl_GetVar(pTcl,SICSERROR,TCL_GLOBAL_ONLY) != NULL)
|
||||
{
|
||||
Tcl_UnsetVar(pTcl,SICSERROR,TCL_GLOBAL_ONLY);
|
||||
strncpy(pBueffel,pTcl->result,1023);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
}
|
||||
SCPrintf(pCon,eError,"%s",pTcl->result);
|
||||
return 0;
|
||||
}
|
||||
return 1; /* not reached */
|
||||
@@ -990,16 +978,21 @@ static int ProtectedExec(ClientData clientData, Tcl_Interp *interp,
|
||||
int TransactAction(SConnection *pCon, SicsInterp *pSics, void *pData,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
char pCommand[1024], pStart[1024];
|
||||
char pBuffer[1024];
|
||||
char *pCommand;
|
||||
int iRet;
|
||||
|
||||
Arg2Text(argc-1,&argv[1],pCommand,1023);
|
||||
pCommand = Arg2Tcl(argc-1,&argv[1],pBuffer, sizeof(pBuffer));
|
||||
if (!pCommand) {
|
||||
SCWrite(pCon,"ERROR: no memory", eError);
|
||||
return 0;
|
||||
}
|
||||
strtolower(argv[0]);
|
||||
if(strcmp(argv[0],"fulltransact") == 0){
|
||||
snprintf(pStart,1023,"TRANSACTIONSTART %s",pCommand);
|
||||
SCWrite(pCon,pStart,eError);
|
||||
SCPrintf(pCon,eError, "TRANSACTIONSTART %s",pCommand);
|
||||
}
|
||||
iRet = InterpExecute(pSics,pCon,pCommand);
|
||||
if (pCommand != pBuffer) free(pCommand);
|
||||
SCWrite(pCon,"TRANSACTIONFINISHED",eError);
|
||||
return iRet;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user