From 1e8f102e8cec4ae84f09cc595013234398270366 Mon Sep 17 00:00:00 2001 From: Eric Paris Date: Tue, 5 Feb 2013 19:15:42 -0500 Subject: [PATCH] libselinux: src/label_android_property: do not leak fd on error We were opening the path, but if the fstat failed or it was not a regular file we would return without closing the fd. Fix my using the common error exit path rather than just returning. Signed-off-by: Eric Paris --- libselinux/src/label_android_property.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libselinux/src/label_android_property.c b/libselinux/src/label_android_property.c index e11ccf89..b00eb074 100644 --- a/libselinux/src/label_android_property.c +++ b/libselinux/src/label_android_property.c @@ -161,11 +161,10 @@ static int init(struct selabel_handle *rec, struct selinux_opt *opts, return -1; if (fstat(fileno(fp), &sb) < 0) - return -1; - if (!S_ISREG(sb.st_mode)) { - errno = EINVAL; - return -1; - } + goto finish; + errno = EINVAL; + if (!S_ISREG(sb.st_mode)) + goto finish; /* * Two passes of the specification file. First is to get the size.