Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP4:Update
dmidecode
util-dont-leak-a-file-descriptor-in-read_file.p...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File util-dont-leak-a-file-descriptor-in-read_file.patch of Package dmidecode
From: Jean Delvare <jdelvare@suse.de> Date: Tue, 11 Apr 2017 11:41:38 +0200 Subject: util: Don't leak a file descriptor in read_file Git-commit: 6953b627a0f11f70662496a77b67aefa9dc40968 Patch-mainline: 3.1 If memory allocation fails, we should close the file descriptor before returning the error. Also remove unneeded parentheses on return, return isn't a function. Signed-off-by: Jean Delvare <jdelvare@suse.de> Fixes: 2339e722b49e ("util: Add read_file() function for reading sysfs files") --- util.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) --- a/util.c +++ b/util.c @@ -113,13 +113,13 @@ void *read_file(size_t *max_len, const c { if (errno != ENOENT) perror(filename); - return(NULL); + return NULL; } if ((p = malloc(*max_len)) == NULL) { perror("malloc"); - return NULL; + goto out; } do @@ -129,10 +129,10 @@ void *read_file(size_t *max_len, const c { if (errno != EINTR) { - close(fd); perror(filename); free(p); - return NULL; + p = NULL; + goto out; } } else @@ -140,8 +140,9 @@ void *read_file(size_t *max_len, const c } while (r != 0); - close(fd); *max_len = r2; +out: + close(fd); return p; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor