ryantimwilson / rpms / systemd

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