diff --git a/evcontroller.c b/evcontroller.c index bcbf1b9f..01d3b208 100644 --- a/evcontroller.c +++ b/evcontroller.c @@ -186,8 +186,6 @@ iRet = self->pDriv->GetValue(self->pDriv,&fPos); - printf("Return: %d Value: %f\n",iRet,fPos); - if(iRet == 0) { self->pDriv->GetError(self->pDriv,&iCode, pError,131); diff --git a/tecs/coc_server.c b/tecs/coc_server.c index 9c8c2578..67335e43 100644 --- a/tecs/coc_server.c +++ b/tecs/coc_server.c @@ -36,7 +36,7 @@ int CocInitServer(int bufsize, int port) { if (bufsize==0) bufsize=1024; ERR_P(buf=str_create_buf(bufsize, '\0')); ERR_P(bufo=str_create_buf(bufsize,'\0')); - cList=malloc(sizeof(*cList)); /* empty header */ + NEW(cList); /* empty header */ /* first try to connect to an existing server */ @@ -81,7 +81,7 @@ int CocHandle1Request(int tmo_msec, int fd) { cl->mode=0; cl->cmd[0]='\0'; cl->res[0]='\0'; - cList=malloc(sizeof(*cList)); + NEW(cList); cList->next=cl; h=gethostbyaddr(&cadr.sin_addr, 4, AF_INET); if (h==NULL) { @@ -99,7 +99,7 @@ int CocHandle1Request(int tmo_msec, int fd) { close(cl->fd); FD_CLR(cl->fd, &mask); cl0->next=cl->next; - free(cl); + my_free(cl); cl=cl0; } else { @@ -233,9 +233,9 @@ void CocCloseServer() { close(cl->fd); cl0=cl; cl=cl->next; - free(cl0); + my_free(cl0); } - free(cList); + my_free(cList); close(mainFd); str_free_buf(buf); str_free_buf(bufo); logfileClose(); diff --git a/tecs/coc_util.c b/tecs/coc_util.c index efce5ded..c33ad85c 100644 --- a/tecs/coc_util.c +++ b/tecs/coc_util.c @@ -146,7 +146,7 @@ CocVar *CocDefVar(const char *name, void *var, int type, int *flag) { assert(varListHdl!=NULL); p=CocFindVar1(*varListHdl, name); if (p==NULL) { - p=malloc(sizeof(*p)); + p=my_malloc(sizeof(*p), name); p->next=*varListHdl; *varListHdl=p; str_copy(p->name, name); @@ -238,7 +238,8 @@ void CocFreeVarList(CocVar **varList) { p=v; v=p->next; p->next=NULL; - free(p); + printf("my_free %s\n", p->name); + my_free(p); } *varList=NULL; } diff --git a/tecs/err_handling.c b/tecs/err_handling.c index e7d06669..a17d2bd5 100644 --- a/tecs/err_handling.c +++ b/tecs/err_handling.c @@ -15,6 +15,18 @@ char *ErrMessage=NULL; void (*outrtn)()=NULL; void *outarg; +void *my_malloc(size_t size, const char *text) { + void *ptr; + ptr=calloc(1,size); +/* printf("new %s %X %d\n", text, ptr, size); */ + return(ptr); +} + +void my_free(void *ptr) { +/* printf("my_free %X\n", ptr); */ + free(ptr); +} + void ErrTxt(char *text, int systemError) { if (systemError) { sp=0; ErrCode=errno; ErrMessage=strerror(errno); } diff --git a/tecs/err_handling.h b/tecs/err_handling.h index 88110dee..6183ea93 100644 --- a/tecs/err_handling.h +++ b/tecs/err_handling.h @@ -1,6 +1,9 @@ #ifndef _ERR_HANDLING_H_ #define _ERR_HANDLING_H_ +#ifdef FORTIFY +#include "fortify.h" +#endif #include #include @@ -71,6 +74,8 @@ Global Variables (read only) #define ERR_MSG(R) { ErrMsg(R); goto OnError; } #define ERR_COD(R) { ErrCod(R); goto OnError; } +#define NEW(PTR) ERR_SP(PTR=my_malloc(sizeof(*PTR),#PTR)) + void ErrTxt(char *text, int systemError); void ErrMsg(char *msg); void ErrCod(int code); @@ -79,6 +84,8 @@ void ERR_EXIT(char *text); void ErrLog(char *text); void ErrSetOutRtn(void (*rtn)(), void *arg); void ErrSetOutFile(FILE *file); +void *my_malloc(size_t size, const char *text); +void my_free(void *ptr); extern int ErrCode; extern char *ErrMessage; diff --git a/tecs/str_buf.c b/tecs/str_buf.c index aa135d9b..443f105d 100644 --- a/tecs/str_buf.c +++ b/tecs/str_buf.c @@ -158,8 +158,8 @@ void str_put_start(Str_Buf *buf) Str_Buf *str_create_buf(size_t size, char separator) { Str_Buf *buf; - ERR_P(buf=malloc(sizeof(*buf))); - ERR_P(buf->buf=malloc(size)); + NEW(buf); + ERR_P(buf->buf=my_malloc(size, "buf")); buf->dsize=size; buf->sep=separator; buf->wrpos=0; @@ -183,6 +183,6 @@ void str_link_buf(Str_Buf *buf, char *str, int size, char separator) { } void str_free_buf(Str_Buf *buf) -{ free(buf->buf); - free(buf); +{ my_free(buf->buf); + my_free(buf); } diff --git a/tecs/str_util.c b/tecs/str_util.c index 9d4346ce..e3899681 100644 --- a/tecs/str_util.c +++ b/tecs/str_util.c @@ -113,7 +113,7 @@ char *str_read_file(char *file) { i=stat(file, &statbuf); if (i<0) ERR_MSG("file not found"); size=statbuf.st_size+4; - ERR_SP(str=malloc(size)); + ERR_SP(str=my_malloc(size, file)); e=&str[size-1]; ERR_SP(fil=fopen(file, "r")); s=str; diff --git a/tecs/tecs.c b/tecs/tecs.c index 219832fa..60ecedd5 100644 --- a/tecs/tecs.c +++ b/tecs/tecs.c @@ -161,7 +161,7 @@ int instCurve(char *nam, char *channel) { str_append(buf, " "); str_upcase(buf, buf); - if (cache==NULL) { cache=malloc(1); *cache='\0'; } /* create empty cache if undefined */ + if (cache==NULL) { ERR_SP(cache=my_malloc(1,"one")); *cache='\0'; } /* create empty cache if undefined */ start=strchr(cache, '\n'); /* skip device names */ if (start==NULL) { start=cache; } else { start++; } entry=strstr(start, buf); @@ -251,7 +251,7 @@ int instCurve(char *nam, char *channel) { logfileOut(LOG_MAIN, "curve selected on channel %s\n", chan); saveTime=tim+30; } - free(crv); crv=NULL; + my_free(crv); crv=NULL; if (num<=20) return(0); /* standard curve, do not touch cache */ @@ -276,15 +276,16 @@ int instCurve(char *nam, char *channel) { ERR_SI(fputs("\n", fil)); ERR_SI(fputs(e, fil)); } + ERR_SI(fputc('\0', fil)); ERR_SI(fclose(fil)); fil=NULL; - free(cache); + my_free(cache); /* re-read it */ ERR_P(cache=str_read_file(nbuf)); return(0); OnError: - if (crv!=NULL) free(crv); + if (crv!=NULL) my_free(crv); if (fil!=NULL) fclose(fil); return(retstat); } @@ -303,7 +304,7 @@ int configInput() { sprintf(buf, "%+d ", testpoint->code); if (testpoint->code==0) return(0); } - if (table!=NULL && tim>tableTime+60) { free(table); table=NULL; }; /* clear old table */ + if (table!=NULL && tim>tableTime+60) { my_free(table); table=NULL; }; /* clear old table */ if (table==NULL) { /* read table */ str_copy(nbuf, binDir); str_append(nbuf, TABLE_FILE); @@ -520,7 +521,7 @@ int PeriodicTask() { if (samp.manual || samp.code!=0) { samp.dirty=1; } ERR_P(LscCmd(ser, "RANGE:0")); /* switch off heater */ /* reload curve cache: */ - if (cache!=NULL) free(cache); + if (cache!=NULL) my_free(cache); sprintf(lbuf, "lsc.%d", serialNo); str_copy(buf, logDir); str_append(buf, lbuf); diff --git a/tecs/tecs_cli.c b/tecs/tecs_cli.c index c2ec1c83..1090e9c3 100644 --- a/tecs/tecs_cli.c +++ b/tecs/tecs_cli.c @@ -11,7 +11,7 @@ static float tempX, tempP, tempC; pTecsClient TeccInit(char *startcmd, int port) { CocConn *conn; - ERR_SP(conn=(CocConn *)malloc(sizeof(*conn))); + ERR_SP(conn=(CocConn *)my_malloc(sizeof(*conn),"conn")); ERR_I(CocInitClient(conn, "", port, "#rwacs", 0, startcmd)); CocDefFlt(tempC, CocRD); CocDefFlt(tempP, CocRD); @@ -135,7 +135,7 @@ int TeccQuitServer(pTecsClient conn) { void TeccClose(pTecsClient conn) { if (conn!=NULL) { CocCloseClient(conn); - free(conn); + my_free(conn); } } diff --git a/tecs/tecs_serial.c b/tecs/tecs_serial.c index 6b0049b6..37e26263 100644 --- a/tecs/tecs_serial.c +++ b/tecs/tecs_serial.c @@ -35,7 +35,7 @@ SerChannel *SerOpen(const char *host, int msecTmo, void (*idleHdl)(int,int)) { int port, chan; idleHandler=idleHdl; - ser=calloc(1, sizeof(*ser)); + NEW(ser); str_copy(hbuf, host); p=str_split(ser->asyn_info.host, hbuf, ':'); port=4000; diff --git a/tecsdriv.c b/tecsdriv.c index a15d71a5..caa2993a 100644 --- a/tecsdriv.c +++ b/tecsdriv.c @@ -152,8 +152,7 @@ if (now!=lastGet) { /* TecsGet was not yet called within this second */ lastGet=now; } else { - CocDelay(500); /* wait 0.5 sec. (seems that SICS has nothing else to do then reading temperatures) */ - printf("usleep %d\n", now); + CocDelay(200); /* wait 0.2 sec. (seems that SICS has nothing else to do then reading temperatures) */ } /* get temperature */ diff --git a/tecsdriv.h b/tecsdriv.h index 50f20939..d38b69a0 100644 --- a/tecsdriv.h +++ b/tecsdriv.h @@ -22,4 +22,6 @@ int TecsWrapper(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]); + int TecsError(pEVDriver self, int *iCode, char *error, int iErrLen); + #endif