From 394dc40b9724624a0542fcf4d3e6c9d2f9a0aa4c Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Sat, 3 Jan 2009 19:33:24 +0000 Subject: [PATCH] Add mechanism to free old leap table To avoid memory leaks, we add a simple internal mechanism to free the table of leap seconds if it was previously loaded from disk. The user is still responsible for freeing their own tables, of course. --- src/libiso8601/100_leap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libiso8601/100_leap.c b/src/libiso8601/100_leap.c index 9257976..20647de 100644 --- a/src/libiso8601/100_leap.c +++ b/src/libiso8601/100_leap.c @@ -73,8 +73,13 @@ int iso8601_leap_elapsed(const struct iso8601_date* start, const struct iso8601_ +static int leap_table_free_old = 0; + void iso8601_leap_table_set(int* new_table, int new_size) { + if(leap_table_free_old) free(leap_second_days); + leap_table_free_old = 0; + leap_second_days = new_table; leap_second_days_num = new_size; } @@ -133,6 +138,7 @@ int iso8601_leap_table_load(const char* fname) TEMP_FAILURE_RETRY( close(fd) ); iso8601_leap_table_set(days, new_size); + leap_table_free_old = 1; return 0; #undef GET_UINT32