[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
- Re: Make mv work better with SELinux., (continued)
- Re: Make mv work better with SELinux., Pádraig Brady, 2012/11/27
- [PATCH 4/9] cp: -Z: s/fprintf/error/, Pádraig Brady, 2012/11/27
- [PATCH 6/9] cp: -Z: add selinux.c to POTFILES.in, Pádraig Brady, 2012/11/27
- [PATCH 3/9] cp: -Z: spelling fixes, Pádraig Brady, 2012/11/27
- [PATCH 7/9] cp: -Z: remove redundant includes from selinux.[ch], Pádraig Brady, 2012/11/27
- [PATCH 5/9] cp: -Z: wrap/clarify/isolate --help messages, Pádraig Brady, 2012/11/27
- [PATCH 2/9] cp: -Z: formatting cleanups, Pádraig Brady, 2012/11/27
- [PATCH 8/9] cp: -Z: fix a logic error due to incorrect braces in mkfifo, Pádraig Brady, 2012/11/27
- [PATCH 1/9] cp: -Z: adjust utils to run restorecon with -Z, Pádraig Brady, 2012/11/27
- [PATCH 9/9] cp: -Z: adjust an existing selinux test to the new scheme, Pádraig Brady, 2012/11/27
- [PATCH] cp: -Z: fix memory leak edge case,
Pádraig Brady <=
- Re: Make mv work better with SELinux., Jim Meyering, 2012/11/29