Add a RELEASE_BB_BUFFER macro and use it to fix a memory leak in syslogd.c

(noted by Adam Slattery).
This commit is contained in:
Matt Kraai 2001-07-19 15:00:14 +00:00
parent 81108e7653
commit c1cda4a609
4 changed files with 8 additions and 0 deletions

View File

@ -69,13 +69,16 @@ extern const struct BB_applet applets[];
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK #ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len] #define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len] #define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
#define RELEASE_BB_BUFFER(buffer) ((void)0)
#else #else
#ifdef BB_FEATURE_BUFFERS_GO_IN_BSS #ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
#define RESERVE_BB_BUFFER(buffer,len) static char buffer[len] #define RESERVE_BB_BUFFER(buffer,len) static char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len] #define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
#define RELEASE_BB_BUFFER(buffer) ((void)0)
#else #else
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len) #define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
#define RELEASE_BB_BUFFER(buffer) free (buffer)
#endif #endif
#endif #endif

View File

@ -69,13 +69,16 @@ extern const struct BB_applet applets[];
#ifdef BB_FEATURE_BUFFERS_GO_ON_STACK #ifdef BB_FEATURE_BUFFERS_GO_ON_STACK
#define RESERVE_BB_BUFFER(buffer,len) char buffer[len] #define RESERVE_BB_BUFFER(buffer,len) char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len] #define RESERVE_BB_UBUFFER(buffer,len) unsigned char buffer[len]
#define RELEASE_BB_BUFFER(buffer) ((void)0)
#else #else
#ifdef BB_FEATURE_BUFFERS_GO_IN_BSS #ifdef BB_FEATURE_BUFFERS_GO_IN_BSS
#define RESERVE_BB_BUFFER(buffer,len) static char buffer[len] #define RESERVE_BB_BUFFER(buffer,len) static char buffer[len]
#define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len] #define RESERVE_BB_UBUFFER(buffer,len) static unsigned char buffer[len]
#define RELEASE_BB_BUFFER(buffer) ((void)0)
#else #else
#define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len) #define RESERVE_BB_BUFFER(buffer,len) char *buffer=xmalloc(len)
#define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len) #define RESERVE_BB_UBUFFER(buffer,len) unsigned char *buffer=xmalloc(len)
#define RELEASE_BB_BUFFER(buffer) free (buffer)
#endif #endif
#endif #endif

View File

@ -431,6 +431,7 @@ static int serveConnection (int conn)
/* Now log it */ /* Now log it */
logMessage (pri, line); logMessage (pri, line);
} }
RELEASE_BB_BUFFER (tmpbuf);
return n_read; return n_read;
} }

View File

@ -431,6 +431,7 @@ static int serveConnection (int conn)
/* Now log it */ /* Now log it */
logMessage (pri, line); logMessage (pri, line);
} }
RELEASE_BB_BUFFER (tmpbuf);
return n_read; return n_read;
} }