Revision: 2049 http://geany.svn.sourceforge.net/geany/?rev=2049&view=rev Author: eht16 Date: 2007-11-17 05:09:19 -0800 (Sat, 17 Nov 2007)
Log Message: ----------- Fix possible memory leak and add time_t argument in utils_get_date_time() to pass a time pointer to use.
Modified Paths: -------------- trunk/ChangeLog trunk/src/templates.c trunk/src/utils.c trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2007-11-14 16:44:45 UTC (rev 2048) +++ trunk/ChangeLog 2007-11-17 13:09:19 UTC (rev 2049) @@ -1,3 +1,10 @@ +2007-11-17 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de> + + * src/templates.c, src/utils.c, src/utils.h: + Fix possible memory leak and add time_t argument in + utils_get_date_time() to pass a time pointer to use. + + 2007-11-14 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
* plugins/vcdiff.c, plugins/Makefile.am:
Modified: trunk/src/templates.c =================================================================== --- trunk/src/templates.c 2007-11-14 16:44:45 UTC (rev 2048) +++ trunk/src/templates.c 2007-11-17 13:09:19 UTC (rev 2049) @@ -350,8 +350,8 @@
void templates_init(void) { - gchar *year = utils_get_date_time("%Y"); - gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT); + gchar *year = utils_get_date_time("%Y", NULL); + gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT, NULL);
init_general_templates(year, date); init_ft_templates(year, date); @@ -523,7 +523,7 @@ gchar *template = g_strdup(templates[GEANY_TEMPLATE_FILEHEADER]); gchar *shortname; gchar *result; - gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT); + gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL); filetype_id ft_id = filetype_idx; filetype *ft = filetypes[ft_id];
@@ -586,8 +586,8 @@ gchar *templates_get_template_function(gint filetype_idx, const gchar *func_name) { gchar *template = g_strdup(templates[GEANY_TEMPLATE_FUNCTION]); - gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT); - gchar *datetime = utils_get_date_time(TEMPLATE_DATETIME_FORMAT); + gchar *date = utils_get_date_time(TEMPLATE_DATE_FORMAT, NULL); + gchar *datetime = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL); gchar *result;
template = utils_str_replace(template, "{date}", date); @@ -605,7 +605,7 @@
gchar *templates_get_template_changelog(void) { - gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT); + gchar *date = utils_get_date_time(TEMPLATE_DATETIME_FORMAT, NULL); gchar *result = g_strdup(templates[GEANY_TEMPLATE_CHANGELOG]); result = utils_str_replace(result, "{date}", date);
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2007-11-14 16:44:45 UTC (rev 2048) +++ trunk/src/utils.c 2007-11-17 13:09:19 UTC (rev 2049) @@ -881,15 +881,22 @@ }
-gchar *utils_get_date_time(const gchar *format) +gchar *utils_get_date_time(const gchar *format, time_t *time_to_use) { - time_t tp = time(NULL); - const struct tm *tm = localtime(&tp); - gchar *date = g_malloc0(256); + time_t tp; + const struct tm *tm; + gchar *date;
if (format == NULL) return NULL;
+ if (time_to_use != NULL) + tp = *time_to_use; + else + tp = time(NULL); + + tm = localtime(&tp); + date = g_malloc0(256); strftime(date, 256, format, tm); return date; }
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2007-11-14 16:44:45 UTC (rev 2048) +++ trunk/src/utils.h 2007-11-17 13:09:19 UTC (rev 2049) @@ -99,7 +99,7 @@ gint utils_strpos(const gchar* haystack, const gchar * needle);
-gchar *utils_get_date_time(const gchar *format); +gchar *utils_get_date_time(const gchar *format, time_t *time_to_use);
gchar *utils_get_initials(gchar *name);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.