diff options
author | Dmitry Kozlov <xeb@mail.ru> | 2011-01-12 17:32:15 +0300 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2011-01-12 17:32:15 +0300 |
commit | a6266776efbe57dcf56e413d7b406331c5414206 (patch) | |
tree | b1cb7c89332eea075d4d75862f308a951e3f2b52 /accel-pppd | |
parent | 83537ad5c8839c6c006c4a8d5f5b0405f7ac3dae (diff) | |
download | accel-ppp-a6266776efbe57dcf56e413d7b406331c5414206.tar.gz accel-ppp-a6266776efbe57dcf56e413d7b406331c5414206.zip |
fxed memory leak
Diffstat (limited to 'accel-pppd')
-rw-r--r-- | accel-pppd/log.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/accel-pppd/log.c b/accel-pppd/log.c index 428feddf..fc50d277 100644 --- a/accel-pppd/log.c +++ b/accel-pppd/log.c @@ -44,6 +44,7 @@ static mempool_t chunk_pool; static __thread struct ppp_t *cur_ppp; static __thread struct _log_msg_t *cur_msg; static __thread char *stat_buf; +static pthread_key_t stat_buf_key; static FILE *emerg_file; static FILE *debug_file; @@ -54,13 +55,20 @@ static int add_msg(struct _log_msg_t *msg, const char *buf); //static struct log_pd_t *find_pd(struct ppp_t *ppp); static void write_msg(FILE *f, struct _log_msg_t *msg, struct ppp_t *ppp); +static void stat_buf_free(void *ptr) +{ + _free(ptr); +} + static void do_log(int level, const char *fmt, va_list ap, struct ppp_t *ppp) { struct log_target_t *t; struct log_msg_t *m; - if (!stat_buf) + if (!stat_buf) { stat_buf = _malloc(LOG_MAX_SIZE + 1); + pthread_setspecific(stat_buf_key, stat_buf); + } vsnprintf(stat_buf, LOG_MAX_SIZE, fmt, ap); @@ -488,6 +496,8 @@ static void __init log_init(void) .sa_handler = sighup, }; + pthread_key_create(&stat_buf_key, stat_buf_free); + msg_pool = mempool_create(sizeof(struct log_msg_t)); _msg_pool = mempool_create(sizeof(struct _log_msg_t)); chunk_pool = mempool_create(sizeof(struct log_chunk_t) + LOG_CHUNK_SIZE + 1); |