diff options
author | Gerardo Exequiel Pozzi <djgera@exequiel.ban2.ar> | 2009-05-24 16:58:42 -0300 |
---|---|---|
committer | Aaron Griffin <aaronmgriffin@gmail.com> | 2009-06-12 08:44:38 -0700 |
commit | ef21324f73efe5ca7777d9acc3a262de2294f371 (patch) | |
tree | 6767d07b5dd50511fa14708b1e3242313f14e8eb /minilogd.c | |
parent | 5e0ac3a1759134a63936e7a3dcf2c4378b934617 (diff) |
Fix minilogd.c eat memory on buflines>=MAX_BUF_LINES
Do not allocate more memory and leak when buflines>=MAX_BUF_LINES
Signed-off-by: Gerardo Exequiel Pozzi <djgera@exequiel.ban2.ar>
Signed-off-by: Aaron Griffin <aaronmgriffin@gmail.com>
Diffstat (limited to 'minilogd.c')
-rw-r--r-- | minilogd.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -110,7 +110,9 @@ void runDaemon(int sock) { cleanup(-1); } if ( (x>0) && pfds.revents & (POLLIN | POLLPRI)) { - message = calloc(BUF_LINE_SIZE,sizeof(char)); + if (message == NULL) { + message = calloc(BUF_LINE_SIZE,sizeof(char)); + } recvsock = accept(sock,(struct sockaddr *) &addr, &addrlen); alarm(2); signal(SIGALRM, alarm_handler); @@ -126,6 +128,7 @@ void runDaemon(int sock) { buffer = malloc(sizeof(char *)); message[strlen(message)]='\n'; buffer[buflines]=message; + message = NULL; buflines++; } } @@ -148,6 +151,7 @@ void runDaemon(int sock) { printf("st_mtime: %d %d\n", s1.st_mtime, s2.st_mtime);*/ } } + free(message); cleanup(0); } |