diff options
author | Michal Marek <mmarek@suse.cz> | 2009-07-22 09:48:32 +0000 |
---|---|---|
committer | Michal Marek <mmarek@suse.cz> | 2009-07-22 09:48:32 +0000 |
commit | 4c207a004cce51e0dcd11c42eda514bd1587e8b2 (patch) | |
tree | cefd40c8d71b7fb2585965dd001cf2cc10fd7c55 /lib/gtls.c | |
parent | 650543a042d59d30d3ae0bf4f171077aeb08601b (diff) | |
download | curl-4c207a004cce51e0dcd11c42eda514bd1587e8b2.tar.gz |
- David Binderman found a memory and fd leak in lib/gtls.c:load_file()
(https://bugzilla.novell.com/523919). When looking at the code, I found
that also the ptr pointer can leak.
Diffstat (limited to 'lib/gtls.c')
-rw-r--r-- | lib/gtls.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/gtls.c b/lib/gtls.c index 002246a0c..d5c8f1a79 100644 --- a/lib/gtls.c +++ b/lib/gtls.c @@ -148,17 +148,22 @@ static gnutls_datum load_file (const char *file) long filelen; void *ptr; - if (!(f = fopen(file, "r")) - || fseek(f, 0, SEEK_END) != 0 + if (!(f = fopen(file, "r"))) + return loaded_file; + if (fseek(f, 0, SEEK_END) != 0 || (filelen = ftell(f)) < 0 || fseek(f, 0, SEEK_SET) != 0 - || !(ptr = malloc((size_t)filelen)) - || fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { - return loaded_file; + || !(ptr = malloc((size_t)filelen))) + goto out; + if (fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { + free(ptr); + goto out; } loaded_file.data = ptr; loaded_file.size = (unsigned int)filelen; +out: + fclose(f); return loaded_file; } |