From eea82529d1397784f4ab2c743928dc69e7d48357 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Thu, 4 Nov 2010 14:49:35 +0300 Subject: [PATCH] Ticket #2409: prepare to the 4.7.5 release. (mc_fhl_parse_get_extensions): fixed possible memory leak and minor optimization. Signed-off-by: Andrew Borodin --- lib/filehighlight/ini-file-read.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/filehighlight/ini-file-read.c b/lib/filehighlight/ini-file-read.c index ad254d469..0a23e51d2 100644 --- a/lib/filehighlight/ini-file-read.c +++ b/lib/filehighlight/ini-file-read.c @@ -132,35 +132,33 @@ mc_fhl_parse_get_extensions (mc_fhl_t * fhl, const gchar * group_name) { mc_fhl_filter_t *mc_filter; gchar **exts, **exts_orig; - gchar *esc_ext; gsize exts_size; - GString *buf = g_string_new (""); + GString *buf; exts_orig = exts = mc_config_get_string_list (fhl->config, group_name, "extensions", &exts_size); - if (exts_orig == NULL) - return FALSE; - - if (exts_orig[0] == NULL) { + if (exts_orig == NULL || exts_orig[0] == NULL) + { g_strfreev (exts_orig); return FALSE; } - while (*exts != NULL) { + buf = g_string_sized_new (64); + for (exts = exts_orig; *exts != NULL; exts++) + { + char *esc_ext; + esc_ext = strutils_regex_escape (*exts); if (buf->len != 0) g_string_append_c (buf, '|'); g_string_append (buf, esc_ext); g_free (esc_ext); - exts++; } g_strfreev (exts_orig); - esc_ext = g_string_free (buf, FALSE); - buf = g_string_new (".*\\.("); - g_string_append (buf, esc_ext); + + g_string_prepend (buf, ".*\\.("); g_string_append (buf, ")$"); - g_free (esc_ext); mc_filter = g_new0 (mc_fhl_filter_t, 1); mc_filter->type = MC_FLHGH_T_FREGEXP; -- 2.11.4.GIT