From 167ab418886e42c823f833a590feccd4841820d1 Mon Sep 17 00:00:00 2001 From: Gerardo Exequiel Pozzi Date: Sun, 24 May 2009 16:58:42 -0300 Subject: [PATCH 1/2] 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 --- minilogd.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/minilogd.c b/minilogd.c index d14c9a3..becfc94 100644 --- a/minilogd.c +++ b/minilogd.c @@ -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); } -- 1.6.3.1