summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2017-02-07 02:17:55 +0100
committerGravatar Nikias Bassen2017-02-07 02:17:55 +0100
commiteb929319388cb7f48141b3fde062a8392fe4c00d (patch)
tree6d546817bd787793533dde98eb4493dd637bcab8 /tools
parentcf9ee441ae0ef0dff4f16c3a7f5652ed113ff7bc (diff)
downloadlibplist-eb929319388cb7f48141b3fde062a8392fe4c00d.tar.gz
libplist-eb929319388cb7f48141b3fde062a8392fe4c00d.tar.bz2
plistutil: Print error message when opening input/output file fails and plug memory leaks on error
Diffstat (limited to 'tools')
-rw-r--r--tools/plistutil.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/plistutil.c b/tools/plistutil.c
index 7652bdc..a1a8c9c 100644
--- a/tools/plistutil.c
+++ b/tools/plistutil.c
@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
+#include <errno.h>
#ifdef _MSC_VER
#pragma warning(disable:4996)
@@ -124,14 +125,18 @@ int main(int argc, char *argv[])
// read input file
iplist = fopen(options->in_file, "rb");
if (!iplist) {
+ printf("ERROR: Could not open input file '%s': %s\n", options->in_file, strerror(errno));
free(options);
return 1;
}
- stat(options->in_file, &filestats);
+ memset(&filestats, '\0', sizeof(struct stat));
+ fstat(fileno(iplist), &filestats);
if (filestats.st_size < 8) {
printf("ERROR: Input file is too small to contain valid plist data.\n");
+ free(options);
+ fclose(iplist);
return -1;
}
@@ -159,6 +164,7 @@ int main(int argc, char *argv[])
{
FILE *oplist = fopen(options->out_file, "wb");
if (!oplist) {
+ printf("ERROR: Could not open output file '%s': %s\n", options->out_file, strerror(errno));
free(options);
return 1;
}