ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
803fb7
From 28b5692e9ab3dbb07e4d6b8e44b370637c04ba86 Mon Sep 17 00:00:00 2001
803fb7
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
803fb7
Date: Sat, 7 Mar 2015 14:19:20 -0500
803fb7
Subject: [PATCH] nspawn: fix use-after-free and leak in error paths
803fb7
803fb7
CID #1257765.
803fb7
803fb7
(cherry picked from commit 8a16a7b4e7f6702a7e6edaead80ecf04be7d3ba2)
803fb7
---
803fb7
 src/nspawn/nspawn.c | 4 ++--
803fb7
 1 file changed, 2 insertions(+), 2 deletions(-)
803fb7
803fb7
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
803fb7
index 7724df96b..78bd58483 100644
803fb7
--- a/src/nspawn/nspawn.c
803fb7
+++ b/src/nspawn/nspawn.c
803fb7
@@ -3627,7 +3627,7 @@ int main(int argc, char *argv[]) {
803fb7
                 }
803fb7
 
803fb7
                 if (arg_ephemeral) {
803fb7
-                        char *np;
803fb7
+                        _cleanup_free_ char *np = NULL;
803fb7
 
803fb7
                         /* If the specified path is a mount point we
803fb7
                          * generate the new snapshot immediately
803fb7
@@ -3657,13 +3657,13 @@ int main(int argc, char *argv[]) {
803fb7
 
803fb7
                         r = btrfs_subvol_snapshot(arg_directory, np, arg_read_only, true);
803fb7
                         if (r < 0) {
803fb7
-                                free(np);
803fb7
                                 log_error_errno(r, "Failed to create snapshot %s from %s: %m", np, arg_directory);
803fb7
                                 goto finish;
803fb7
                         }
803fb7
 
803fb7
                         free(arg_directory);
803fb7
                         arg_directory = np;
803fb7
+                        np = NULL;
803fb7
 
803fb7
                         remove_subvol = true;
803fb7