From: darkcoven Date: Sun, 30 Dec 2012 15:31:21 +0000 (+0100) Subject: Lib: fixed memory leaks. X-Git-Url: https://git.sur5r.net/?p=ngadmin;a=commitdiff_plain;h=10a6bf9cce2312c045bf9997b9404a24fe22952d Lib: fixed memory leaks. Added the possibility to build debug and release versions. Lib: removed unused commented code. --- diff --git a/.gitignore b/.gitignore index 5240222..777604b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,6 @@ *~ *.so admin -emu +admind +lib/doc/ +brouillon diff --git a/cli/Makefile b/cli/Makefile index a477b71..c18c9a4 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -1,13 +1,22 @@ CC=gcc -CFLAGS=-I../lib -W -Wall -Wextra -Os -fomit-frame-pointer -LDFLAGS=-L../lib -lngadmin -lreadline -s -EXEC=admin +CFLAGS=-I../lib -W -Wall -Wextra -Os +LDFLAGS=-L../lib -lreadline SRC=$(wildcard *.c) OBJ=$(SRC:.c=.o) +ifeq ($(DEBUG), yes) +EXEC=admind +CFLAGS+=-g +LDFLAGS+=-lngadmind -g +else +EXEC=admin +CFLAGS+=-fomit-frame-pointer +LDFLAGS+=-lngadmin -s +endif + $(EXEC): $(OBJ) $(CC) $^ -o $@ $(LDFLAGS) diff --git a/lib/doc/.gitignore b/lib/doc/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/lib/doc/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/lib/src/Makefile b/lib/src/Makefile index e936938..7251591 100644 --- a/lib/src/Makefile +++ b/lib/src/Makefile @@ -1,13 +1,22 @@ CC=gcc -CFLAGS=-DBUILD_LIB -I.. -W -Wall -Wextra -Os -fomit-frame-pointer -fno-strict-aliasing -fvisibility=hidden -fPIC -LDFLAGS=-s -EXEC=../libngadmin.so +CFLAGS=-DBUILD_LIB -I.. -W -Wall -Wextra -Os -fno-strict-aliasing -fvisibility=hidden -fPIC +LDFLAGS= SRC=$(wildcard *.c) OBJ=$(SRC:.c=.o) +ifeq ($(DEBUG), yes) +EXEC=../libngadmind.so +CFLAGS+=-g +LDFLAGS+=-g +else +EXEC=../libngadmin.so +CFLAGS+=-fomit-frame-pointer +LDFLAGS+=-s +endif + $(EXEC): $(OBJ) $(CC) $^ -shared -o $@ $(LDFLAGS) diff --git a/lib/src/network.c b/lib/src/network.c index a7b01d1..4df887e 100644 --- a/lib/src/network.c +++ b/lib/src/network.c @@ -129,30 +129,6 @@ int updateTimeout (struct ngadmin *nga) { } -/* -// --------------------------------------------------------- -int connectSwitch (struct ngadmin *nga, struct swi_attr *sa) { - - struct sockaddr_in remote; - - - memset(&remote, 0, sizeof(struct sockaddr_in)); - remote.sin_family=AF_UNSPEC; - remote.sin_port=htons(SWITCH_PORT); - - nga->current=sa; - - if ( sa!=NULL && !nga->keepbroad ) { - remote.sin_family=AF_INET; - remote.sin_addr=sa->nc.ip; - } - - - return connect(nga->sock, (struct sockaddr*)&remote, sizeof(struct sockaddr_in)); - -} -*/ - // ---------------------------------------------------------------- int sendNgPacket (struct ngadmin *nga, char code, const List *attr) { @@ -166,8 +142,6 @@ int sendNgPacket (struct ngadmin *nga, char code, const List *attr) { int ret; - - np.buffer=buffer; np.maxlen=sizeof(buffer); initNgPacket(&np); @@ -199,38 +173,6 @@ int sendNgPacket (struct ngadmin *nga, char code, const List *attr) { } -/* -static int my_poll (struct pollfd *fds, nfds_t nfds, struct timeval *timeout) { - - int ret, rem=-1; - struct timeval start, stop; - - - if ( timeout!=NULL ) { - if ( timeout->tv_sec<0 || timeout->tv_usec<0 ) rem=0; - else rem=timeout->tv_sec*1000+timeout->tv_usec/1000; - } - - gettimeofday(&start, NULL); - ret=poll(fds, nfds, rem); - gettimeofday(&stop, NULL); - - if ( timeout!=NULL ) { - rem-=(stop.tv_sec-start.tv_sec)*1000+(stop.tv_usec-start.tv_usec)/1000; - if ( ret<=0 || rem<0 ) rem=0; - printf("tv_sec = %i, tv_usec = %i\n", start.tv_sec, start.tv_usec); - printf("tv_sec = %i, tv_usec = %i\n", stop.tv_sec, stop.tv_usec); - printf("rem = %i\n", rem); - timeout->tv_sec=rem/1000; - timeout->tv_usec=(rem%1000)*1000; - } - - - return ret; - -} -*/ - // ------------------------------------------------------------------------------------------------------------ int recvNgPacket (struct ngadmin *nga, char code, unsigned char *error, unsigned short *attr_error, List *attr) { @@ -241,7 +183,6 @@ int recvNgPacket (struct ngadmin *nga, char code, unsigned char *error, unsigned socklen_t slen=sizeof(struct sockaddr_in); const struct swi_attr *sa=nga->current; struct timeval rem; - //struct pollfd fds; fd_set fs; int len=-1; @@ -253,12 +194,8 @@ int recvNgPacket (struct ngadmin *nga, char code, unsigned char *error, unsigned rem=nga->timeout; - //fds.fd=nga->sock; - //fds.events=POLLIN; - while ( 1 ) { - //my_poll(&fds, 1, &rem); FD_ZERO(&fs); FD_SET(nga->sock, &fs); select(nga->sock+1, &fs, NULL, NULL, &rem); // FIXME: non portable diff --git a/lib/src/ngadmin.c b/lib/src/ngadmin.c index 7b71922..f9d2610 100644 --- a/lib/src/ngadmin.c +++ b/lib/src/ngadmin.c @@ -226,6 +226,8 @@ int ngadmin_scan (struct ngadmin *nga) { nga->swi_count=swiList->count; nga->swi_tab=convertToArray(swiList, sizeof(struct swi_attr)); + destroyList(swiList, free); + destroyList(attr, (void(*)(void*))freeAttr); return ERR_OK; @@ -363,6 +365,7 @@ int ngadmin_getPortsStatus (struct ngadmin *nga, unsigned char *ports) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -444,6 +447,7 @@ int ngadmin_getPortsStatistics (struct ngadmin *nga, struct port_stats *ps) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -534,6 +538,7 @@ int ngadmin_getStormFilterState (struct ngadmin *nga, int *s) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -590,6 +595,7 @@ int ngadmin_getStormFilterValues (struct ngadmin *nga, int *ports) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -672,6 +678,7 @@ int ngadmin_getBitrateLimits (struct ngadmin *nga, int *ports) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -752,6 +759,7 @@ int ngadmin_getQOSMode (struct ngadmin *nga, int *s) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -1164,6 +1172,7 @@ int ngadmin_cabletest (struct ngadmin *nga, struct cabletest *ct, int nb) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -1254,6 +1263,7 @@ int ngadmin_getVLANType (struct ngadmin *nga, int *t) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -1331,6 +1341,7 @@ int ngadmin_getVLANDotAllConf (struct ngadmin *nga, unsigned short *vlans, unsig end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -1379,6 +1390,7 @@ int ngadmin_getVLANDotConf (struct ngadmin *nga, unsigned short vlan, unsigned c end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; } @@ -1454,7 +1466,6 @@ int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsi } - pushBackList(attr, newAttr(ATTR_VLAN_DOT_CONF, 4, p)); ret=writeRequest(nga, attr); attr=NULL; @@ -1463,6 +1474,7 @@ int ngadmin_setVLANDotConf (struct ngadmin *nga, unsigned short vlan, const unsi end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; @@ -1531,6 +1543,7 @@ int ngadmin_getAllPVID (struct ngadmin *nga, unsigned short *ports) { end: destroyList(attr, (void(*)(void*))freeAttr); + return ret; }