diff options
author | Martin Kosek <mkosek@redhat.com> | 2011-11-08 17:59:45 +0100 |
---|---|---|
committer | Simo Sorce <ssorce@redhat.com> | 2012-01-11 12:04:18 -0500 |
commit | 740e0b98cc31e4c11d12968730234963b04b2711 (patch) | |
tree | 956e3a0c85f24a736449fde46e0240609417ec72 /ipa-client/config.c | |
parent | 9630ab2c7e8e74a916a5df0d2a2f8ca883a1b338 (diff) | |
download | freeipa.git-740e0b98cc31e4c11d12968730234963b04b2711.tar.gz freeipa.git-740e0b98cc31e4c11d12968730234963b04b2711.tar.xz freeipa.git-740e0b98cc31e4c11d12968730234963b04b2711.zip |
Fix coverity issues in client CLI tools
This patch fixes 2 coverity issues:
* ipa-client/config.c: CID 11090: Resource leak
* ipa-client/ipa-getkeytab.c: CID 11018: Unchecked return value
https://fedorahosted.org/freeipa/ticket/2035
Diffstat (limited to 'ipa-client/config.c')
-rw-r--r-- | ipa-client/config.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/ipa-client/config.c b/ipa-client/config.c index 493d7402..ecc126ff 100644 --- a/ipa-client/config.c +++ b/ipa-client/config.c @@ -45,28 +45,29 @@ char * read_config_file(const char *filename) { - int fd; + int fd = -1; struct stat st; - char *data, *dest; + char *data = NULL; + char *dest; size_t left; fd = open(filename, O_RDONLY); if (fd == -1) { fprintf(stderr, _("cannot open configuration file %s\n"), filename); - return NULL; + goto error_out; } /* stat() the file so we know the size and can pre-allocate the right * amount of memory. */ if (fstat(fd, &st) == -1) { fprintf(stderr, _("cannot stat() configuration file %s\n"), filename); - return NULL; + goto error_out; } left = st.st_size; data = malloc(st.st_size + 1); if (data == NULL) { fprintf(stderr, _("out of memory\n")); - return NULL; + goto error_out; } dest = data; while (left != 0) { @@ -77,9 +78,7 @@ read_config_file(const char *filename) break; if (res < 0) { fprintf(stderr, _("read error\n")); - close(fd); - free(dest); - return NULL; + goto error_out; } dest += res; left -= res; @@ -87,6 +86,11 @@ read_config_file(const char *filename) close(fd); *dest = 0; return data; + +error_out: + if (fd != -1) close(fd); + free(data); + return NULL; } char * |