summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorRikard Falkeborn <rikard.falkeborn@gmail.com>2015-08-10 21:42:39 +0200
committerAllan McRae <allan@archlinux.org>2015-10-21 07:12:25 +0200
commite28aff4d87f9456c213359adaf7299a882cdcb04 (patch)
treed59eebd99c8f1fa29e584dcd0b7cb5fd4d38660f /src/util
parentaa8a674b6b2c8474a1111b16806c27d4562b5d80 (diff)
downloadpacman-e28aff4d87f9456c213359adaf7299a882cdcb04.tar.gz
pacman-e28aff4d87f9456c213359adaf7299a882cdcb04.tar.xz
pacsort: clean up if error
* free memory * close open file Signed-off-by: Rikard Falkeborn <rikard.falkeborn@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/pacsort.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/util/pacsort.c b/src/util/pacsort.c
index 3337d976..e7dc63e5 100644
--- a/src/util/pacsort.c
+++ b/src/util/pacsort.c
@@ -484,6 +484,7 @@ int main(int argc, char *argv[])
struct list_t *list;
struct buffer_t *buffer;
size_t i;
+ int ret = 0;
/* option defaults */
opts.order = 1;
@@ -507,7 +508,8 @@ int main(int argc, char *argv[])
if(optind == argc) {
if(splitfile(stdin, buffer, list) != 0) {
fprintf(stderr, "%s: memory exhausted\n", argv[0]);
- return ENOMEM;
+ ret = ENOMEM;
+ goto cleanup;
}
} else {
while(optind < argc) {
@@ -515,7 +517,9 @@ int main(int argc, char *argv[])
if(input) {
if(splitfile(input, buffer, list) != 0) {
fprintf(stderr, "%s: memory exhausted\n", argv[0]);
- return ENOMEM;
+ fclose(input);
+ ret = ENOMEM;
+ goto cleanup;
}
fclose(input);
} else {
@@ -534,10 +538,11 @@ int main(int argc, char *argv[])
}
}
+cleanup:
list_free(list, input_free);
buffer_free(buffer);
- return 0;
+ return ret;
}
/* vim: set noet: */