Skip to content

Commit

Permalink
bugfix: zlog_reload can cause a crash by freeing memory used by zlog_…
Browse files Browse the repository at this point in the history
…spec_write_time.

see: #7
  • Loading branch information
HardySimpson committed Sep 20, 2012
1 parent bc3a950 commit acbd8c4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/release.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#define ZLOG_GIT_SHA1 "7aa9b595"
#define ZLOG_GIT_SHA1 "20c44a22"
#define ZLOG_GIT_DIRTY "0"
20 changes: 3 additions & 17 deletions src/spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit acbd8c4

Please sign in to comment.