From bf8ac0594e36c85a023fbde6bbd5ee5c98bb6b94 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 8 Mar 2009 13:22:10 +0300 Subject: [PATCH] src/file.c: move_dir_dir(): * changed type of move_over variable from int to gboolean; * fixed memory leak: destdir is not free'd when the same directory is copied; * don't use the non-valid dbuf variable if mc_stat(d, &dbuf) returns non-zero. --- src/file.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/file.c b/src/file.c index 359d8b82d..0cadad84d 100644 --- a/src/file.c +++ b/src/file.c @@ -1148,7 +1148,8 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d, struct link *lp; char *destdir; FileProgressStatus return_status; - int move_over = 0; + gboolean move_over = FALSE; + gboolean dstat_ok; if (file_progress_show_source (ctx, s) == FILE_ABORT || file_progress_show_target (ctx, d) == FILE_ABORT) @@ -1157,17 +1158,19 @@ move_dir_dir (FileOpContext *ctx, const char *s, const char *d, mc_refresh (); mc_stat (s, &sbuf); - if (mc_stat (d, &dbuf)) + dstat_ok = (mc_stat (d, &dbuf) == 0); + + if (dstat_ok && sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) + return warn_same_file (_(" `%s' \n and \n `%s' \n are the same directory "), s, d); + + if (!dstat_ok) destdir = g_strdup (d); /* destination doesn't exist */ else if (!ctx->dive_into_subdirs) { destdir = g_strdup (d); - move_over = 1; + move_over = TRUE; } else destdir = concat_dir_and_file (d, x_basename (s)); - if (sbuf.st_dev == dbuf.st_dev && sbuf.st_ino == dbuf.st_ino) - return warn_same_file (_(" `%s' \n and \n `%s' \n are the same directory "), s, d); - /* Check if the user inputted an existing dir */ retry_dst_stat: if (!mc_stat (destdir, &destbuf)) {