Permalink
Browse files

bugfix: zlog_reload can cause a crash by freeing memory used by zlog_…

…spec_write_time.

see: #7
  • Loading branch information...
1 parent bc3a950 commit acbd8c417e53e035a976c0836b62cb6f3e1b7de2 @HardySimpson committed Sep 20, 2012
Showing with 4 additions and 19 deletions.
  1. +0 −1 src/event.h
  2. +1 −1 src/release.h
  3. +3 −17 src/spec.c
View
@@ -57,7 +57,6 @@ typedef struct {
char D_time_str[10 + 1 + 8 + 1]; /* YYYY-mm-dd HH:mm:ss */
char time_str[MAXLEN_CFG_LINE + 1];
size_t time_str_len;
- char *last_time_fmt;
pid_t pid;
pid_t last_pid;
View
@@ -1,2 +1,2 @@
-#define ZLOG_GIT_SHA1 "7aa9b595"
+#define ZLOG_GIT_SHA1 "20c44a22"
#define ZLOG_GIT_DIRTY "0"
View
@@ -73,11 +73,9 @@ void zlog_spec_profile(zlog_spec_t * a_spec, int flag)
"%F %T", &(a_thread->event->local_time) ); \
\
/* strftime %d() per second */ \
- if (a_thread->event->last_time_fmt) { \
- a_thread->event->time_str_len = strftime(a_thread->event->time_str, \
+ a_thread->event->time_str_len = strftime(a_thread->event->time_str, \
sizeof(a_thread->event->time_str), \
- a_thread->event->last_time_fmt, &(a_thread->event->local_time)); \
- } \
+ a_spec->time_fmt, &(a_thread->event->local_time)); \
} \
} \
} while(0)
@@ -86,26 +84,14 @@ static int zlog_spec_write_time(zlog_spec_t * a_spec, zlog_thread_t * a_thread,
{
/* do fetch time every event once */
zlog_spec_fetch_time;
-
- /* strftime %d() is slow too, do it when
- * time_fmt changed(event go through another spec) */
- if (a_thread->event->last_time_fmt != a_spec->time_fmt) {
- a_thread->event->last_time_fmt = a_spec->time_fmt;
- a_thread->event->time_str_len = strftime(a_thread->event->time_str,
- sizeof(a_thread->event->time_str),
- a_spec->time_fmt, &(a_thread->event->local_time));
- }
-
return zlog_buf_append(a_buf, a_thread->event->time_str, a_thread->event->time_str_len);
}
static int zlog_spec_write_time_D(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)
{
/* do fetch time every event once */
zlog_spec_fetch_time;
-
- return zlog_buf_append(a_buf, a_thread->event->D_time_str,
- sizeof(a_thread->event->D_time_str) - 1);
+ return zlog_buf_append(a_buf, a_thread->event->D_time_str, sizeof(a_thread->event->D_time_str) - 1);
}
static int zlog_spec_write_ms(zlog_spec_t * a_spec, zlog_thread_t * a_thread, zlog_buf_t * a_buf)

0 comments on commit acbd8c4

Please sign in to comment.