From b757d989030c58af81a100bb7a02c5adb2667bee Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Mon, 3 Nov 2014 21:36:58 +0100 Subject: [PATCH] fix a memleak in rc_migrate_dir --- src/rc.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/rc.c b/src/rc.c index 269aaf6..21183b1 100644 --- a/src/rc.c +++ b/src/rc.c @@ -467,9 +467,9 @@ int rc_save (void) { int rc_migrate_dir (void) { int res; struct stat st_buf; - const gchar* legacy_user_rcdir = NULL; - const gchar* xdg_user_rcdir = NULL; const gchar* xdg_user_dir = NULL; + gchar* legacy_user_rcdir = NULL; + gchar* xdg_user_rcdir = NULL; if (!g_get_user_name () || !g_get_home_dir () || !g_get_user_config_dir ()) { fprintf(stderr, "Unable to get user name/home directory/XDG config directory\n"); @@ -487,11 +487,13 @@ int rc_migrate_dir (void) { res = mkdir (xdg_user_dir, 0755); if (res != 0) { fprintf(stderr, "Can't create XDG user config directory %s\n", xdg_user_dir); + g_free(legacy_user_rcdir); + g_free(xdg_user_rcdir); return res; } } else { - /* move ~/.qf ~/.config/qf */ + /* move ~/.qf ~/.config/xqf */ fprintf(stdout, "Moving legacy config directory %s to XDG user config directory %s\n", legacy_user_rcdir, xdg_user_rcdir); res = rename(legacy_user_rcdir, xdg_user_rcdir); if (res == 0) { @@ -499,6 +501,8 @@ int rc_migrate_dir (void) { } else { fprintf(stderr, "Error when moving legacy config directory %s to XDG user config directory %s\n", legacy_user_rcdir, xdg_user_rcdir); + g_free(legacy_user_rcdir); + g_free(xdg_user_rcdir); return res; } } @@ -506,6 +510,8 @@ int rc_migrate_dir (void) { else if (stat (legacy_user_rcdir, &st_buf) != -1 && stat (xdg_user_rcdir, &st_buf) != -1) { fprintf(stderr, "Warning, there is an old legacy config directory %s, but XDG user config directory %s will be used\n", legacy_user_rcdir, xdg_user_rcdir); } + g_free(legacy_user_rcdir); + g_free(xdg_user_rcdir); return TRUE; }