diff --git a/pressure-vessel/resolve-in-sysroot.c b/pressure-vessel/resolve-in-sysroot.c
index 4b25da6ae8fe95e98c412323ac5450ead9cfa5ef..58a74bc7702ca5f4faf5a21a143f6cd220d455b7 100644
--- a/pressure-vessel/resolve-in-sysroot.c
+++ b/pressure-vessel/resolve-in-sysroot.c
@@ -303,9 +303,6 @@ pv_resolve_in_sysroot (int sysroot,
         }
     }
 
-  if (real_path_out != NULL)
-    *real_path_out = g_string_free (g_steal_pointer (&current_path), FALSE);
-
   if (flags & PV_RESOLVE_FLAGS_READABLE)
     {
       g_autofree char *proc_fd_name = g_strdup_printf ("/proc/self/fd/%d",
@@ -316,9 +313,15 @@ pv_resolve_in_sysroot (int sysroot,
       if (!glnx_openat_rdonly (-1, proc_fd_name, TRUE, &fd, error))
         return -1;
 
+      if (real_path_out != NULL)
+        *real_path_out = g_string_free (g_steal_pointer (&current_path), FALSE);
+
       return glnx_steal_fd (&fd);
     }
 
+  if (real_path_out != NULL)
+    *real_path_out = g_string_free (g_steal_pointer (&current_path), FALSE);
+
   /* Taking the address might look like nonsense here, but it's
    * documented to work: g_array_index expands to fds->data[some_offset].
    * We need to steal ownership of the fd back from @fds so it won't be