diff options
-rw-r--r-- | date.c | 5 | ||||
-rw-r--r-- | date.h | 9 | ||||
-rw-r--r-- | ref-filter.c | 1 | ||||
-rw-r--r-- | t/helper/test-date.c | 2 | ||||
-rwxr-xr-x | t/t0006-date.sh | 2 |
5 files changed, 18 insertions, 1 deletions
@@ -993,6 +993,11 @@ void parse_date_format(const char *format, struct date_mode *mode) die("unknown date format %s", format); } +void date_mode_release(struct date_mode *mode) +{ + free((char *)mode->strftime_fmt); +} + void datestamp(struct strbuf *out) { time_t now; @@ -50,10 +50,17 @@ const char *show_date(timestamp_t time, int timezone, const struct date_mode *mo * * When the "date_mode_type" is DATE_STRFTIME the "strftime_fmt" * member of "struct date_mode" will be a malloc()'d format string to - * be used with strbuf_addftime(). + * be used with strbuf_addftime(), in which case you'll need to call + * date_mode_release() later. */ void parse_date_format(const char *format, struct date_mode *mode); +/** + * Release a "struct date_mode", currently only required if + * parse_date_format() has parsed a "DATE_STRFTIME" format. + */ +void date_mode_release(struct date_mode *mode); + void show_date_relative(timestamp_t time, struct strbuf *timebuf); int parse_date(const char *date, struct strbuf *out); int parse_date_basic(const char *date, timestamp_t *timestamp, int *offset); diff --git a/ref-filter.c b/ref-filter.c index 3399bde932..7838bd22b8 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1276,6 +1276,7 @@ static void grab_date(const char *buf, struct atom_value *v, const char *atomnam goto bad; v->s = xstrdup(show_date(timestamp, tz, &date_mode)); v->value = timestamp; + date_mode_release(&date_mode); return; bad: v->s = xstrdup(""); diff --git a/t/helper/test-date.c b/t/helper/test-date.c index 111071e1dd..45951b1df8 100644 --- a/t/helper/test-date.c +++ b/t/helper/test-date.c @@ -54,6 +54,8 @@ static void show_dates(const char **argv, const char *format) printf("%s -> %s\n", *argv, show_date(t, tz, &mode)); } + + date_mode_release(&mode); } static void parse_dates(const char **argv) diff --git a/t/t0006-date.sh b/t/t0006-date.sh index 794186961e..2490162071 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -1,6 +1,8 @@ #!/bin/sh test_description='test date parsing and printing' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh # arbitrary reference time: 2009-08-30 19:20:00 |