fix a memleak in rc_migrate_dir

This commit is contained in:
Thomas Debesse 2014-11-03 21:36:58 +01:00
parent f56586439d
commit b757d98903

View File

@ -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;
}