diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c
index 871a9f7d21505036049750554f0fcfb2d9ee1c2b..35e4cf8ceafc97550affdbf91bd5f45a44489f13 100644
--- a/thunar/thunar-dialogs.c
+++ b/thunar/thunar-dialogs.c
@@ -881,10 +881,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
   parent_file = thunar_file_get_parent (dst_file, NULL);
   if (parent_file != NULL)
-    {
-      parent_string = thunar_file_get_basename (parent_file);
-      g_object_unref (parent_file);
-    }
+    parent_string = thunar_file_get_basename (parent_file);
 
   if (thunar_file_is_symlink (dst_file))
     /* TRANSLATORS: First part of replace dialog sentence */
@@ -896,6 +893,9 @@ G_GNUC_END_IGNORE_DEPRECATIONS
     /* TRANSLATORS: First part of replace dialog sentence */
     text = g_strdup_printf (_("Replace the existing file in \"%s\""), parent_string);
 
+  if (parent_file != NULL)
+    g_object_unref (parent_file);
+
   /* next row */
   row++;