aboutsummaryrefslogtreecommitdiff
path: root/src/apps
diff options
context:
space:
mode:
authorEven Rouault <even.rouault@spatialys.com>2019-03-26 14:11:34 +0100
committerEven Rouault <even.rouault@spatialys.com>2019-03-26 14:11:34 +0100
commit703805a646f827971135af1b4e60087d88fed974 (patch)
treeb5283d93ae75bbdf0d5801f2955f6e4c81054437 /src/apps
parent01f6d08f0a0d3b05c28d6772d63b506171c59371 (diff)
downloadPROJ-703805a646f827971135af1b4e60087d88fed974.tar.gz
PROJ-703805a646f827971135af1b4e60087d88fed974.zip
optargpm.h: fix memory leaks in error code paths. Coverity CID 193537
Diffstat (limited to 'src/apps')
-rw-r--r--src/apps/optargpm.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/apps/optargpm.h b/src/apps/optargpm.h
index 035c6f92..e7f4f8e5 100644
--- a/src/apps/optargpm.h
+++ b/src/apps/optargpm.h
@@ -534,6 +534,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
*equals = '=';
if (opt_is_flag (o, c)) {
fprintf (stderr, "Option \"%s\" takes no arguments\n", crepr);
+ free (o);
return nullptr;
}
o->optarg[c] = equals + 1;
@@ -544,6 +545,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if (!opt_is_flag (o, c)) {
if ((argc==i + 1) || ('+'==argv[i+1][0]) || ('-'==argv[i+1][0])) {
fprintf (stderr, "Missing argument for option \"%s\"\n", crepr);
+ free (o);
return nullptr;
}
o->optarg[c] = argv[i + 1];
@@ -553,6 +555,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if (!opt_is_flag (o, c)) {
fprintf (stderr, "Expected flag style long option here, but got \"%s\"\n", crepr);
+ free (o);
return nullptr;
}
@@ -564,6 +567,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
/* classic short options */
if (nullptr==o->optarg[c]) {
fprintf (stderr, "Invalid option \"%s\"\n", crepr);
+ free (o);
return nullptr;
}
@@ -580,6 +584,7 @@ OPTARGS *opt_parse (int argc, char **argv, const char *flags, const char *keys,
if ((argc==i + 1) || ('+'==argv[i+1][0]) || ('-'==argv[i+1][0]))
{
fprintf (stderr, "Bad or missing arg for option \"%s\"\n", crepr);
+ free (o);
return nullptr;
}
o->optarg[(int) c] = argv[i + 1];