coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] cp: -Z: fix memory leak edge case


From: Pádraig Brady
Subject: [PATCH] cp: -Z: fix memory leak edge case
Date: Wed, 28 Nov 2012 12:48:16 +0000

From: Bernhard Voelker <address@hidden>

src/selinux.c (defaultcon): In edge cases where scontext is
allocated, while tcontext is not, ensure both are deallocated.
Also remove the redundant NULL guard to context_free().
(restorecon_private): Likewise.
---
 src/selinux.c |   12 ++++--------
 1 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/src/selinux.c b/src/selinux.c
index bbb9999..e708b55 100644
--- a/src/selinux.c
+++ b/src/selinux.c
@@ -128,10 +128,8 @@ defaultcon (char const *path, mode_t mode)
 
 //  printf("defaultcon %s %s\n", path, context_str(tcontext));
 quit:
-  if (scontext)
-    context_free (scontext);
-  if (scontext)
-    context_free (tcontext);
+  context_free (scontext);
+  context_free (tcontext);
   freecon (scon);
   freecon (tcon);
   return rc;
@@ -218,10 +216,8 @@ restorecon_private (char const *path, bool preserve)
 //  printf("restorcon %s %s\n", path, context_str(tcontext));
 quit:
   close (fd);
-  if (scontext)
-    context_free (scontext);
-  if (scontext)
-    context_free (tcontext);
+  context_free (scontext);
+  context_free (tcontext);
   freecon (scon);
   freecon (tcon);
   return rc;
-- 
1.7.6.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]