memory bug corrected

This commit is contained in:
cvs
2000-04-07 14:24:01 +00:00
parent 9c9a2d45a5
commit c70f0b7cb8
12 changed files with 45 additions and 25 deletions

View File

@ -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);

View File

@ -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();

View File

@ -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;
}

View File

@ -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); }

View File

@ -1,6 +1,9 @@
#ifndef _ERR_HANDLING_H_
#define _ERR_HANDLING_H_
#ifdef FORTIFY
#include "fortify.h"
#endif
#include <stdio.h>
#include <sys/errno.h>
@ -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;

View File

@ -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);
}

View File

@ -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;

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 */

View File

@ -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