Add a RELEASE_BB_BUFFER macro and use it to fix a memory leak in syslogd.c
authorMatt Kraai <kraai@debian.org>
Thu, 19 Jul 2001 15:00:14 +0000 (15:00 -0000)
committerMatt Kraai <kraai@debian.org>
Thu, 19 Jul 2001 15:00:14 +0000 (15:00 -0000)
(noted by Adam Slattery).

busybox.h
include/busybox.h
sysklogd/syslogd.c
syslogd.c

index e8055b06c0545b5b996b33d6f83cb2281b9bc637..f79dac8c880f9f705f08d309e74a64b79d82e7f8 100644 (file)
--- a/busybox.h
+++ b/busybox.h
@@ -69,13 +69,16 @@ extern const struct BB_applet applets[];
 #ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
 #define RESERVE_BB_BUFFER(buffer,len)           char buffer[len]
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
+#define RELEASE_BB_BUFFER(buffer)      ((void)0)
 #else
 #ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
 #define RESERVE_BB_BUFFER(buffer,len)  static          char buffer[len]
 #define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
+#define RELEASE_BB_BUFFER(buffer)      ((void)0)
 #else
 #define RESERVE_BB_BUFFER(buffer,len)           char *buffer=xmalloc(len)
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
+#define RELEASE_BB_BUFFER(buffer)      free (buffer)
 #endif
 #endif
 
index e8055b06c0545b5b996b33d6f83cb2281b9bc637..f79dac8c880f9f705f08d309e74a64b79d82e7f8 100644 (file)
@@ -69,13 +69,16 @@ extern const struct BB_applet applets[];
 #ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
 #define RESERVE_BB_BUFFER(buffer,len)           char buffer[len]
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
+#define RELEASE_BB_BUFFER(buffer)      ((void)0)
 #else
 #ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
 #define RESERVE_BB_BUFFER(buffer,len)  static          char buffer[len]
 #define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
+#define RELEASE_BB_BUFFER(buffer)      ((void)0)
 #else
 #define RESERVE_BB_BUFFER(buffer,len)           char *buffer=xmalloc(len)
 #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
+#define RELEASE_BB_BUFFER(buffer)      free (buffer)
 #endif
 #endif
 
index 8ae70a1eda4057d5e72d9c63541d76ffabcad3b5..14219eb541f2b8710d91951abc3362966841f4cc 100644 (file)
@@ -431,6 +431,7 @@ static int serveConnection (int conn)
                /* Now log it */
                logMessage (pri, line);
        }
+       RELEASE_BB_BUFFER (tmpbuf);
        return n_read;
 }
 
index 8ae70a1eda4057d5e72d9c63541d76ffabcad3b5..14219eb541f2b8710d91951abc3362966841f4cc 100644 (file)
--- a/syslogd.c
+++ b/syslogd.c
@@ -431,6 +431,7 @@ static int serveConnection (int conn)
                /* Now log it */
                logMessage (pri, line);
        }
+       RELEASE_BB_BUFFER (tmpbuf);
        return n_read;
 }