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.
This commit is contained in:
parent
73df6f836d
commit
394dc40b97
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue