diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2019-03-02 08:36:46 +0100 |
---|---|---|
committer | Adam Malinowski <a.malinowsk2@partner.samsung.com> | 2019-05-20 11:52:51 +0200 |
commit | edbc2c8e7b8cf87284393a97e482d8eb9288c1aa (patch) | |
tree | 4a2ca5968281677d1d0e67d0234a559101b3a61d | |
parent | 9915f54dbd003ed687394bb07e3e2a9ab426dd9d (diff) | |
download | sd-mux-edbc2c8e7b8cf87284393a97e482d8eb9288c1aa.tar.gz sd-mux-edbc2c8e7b8cf87284393a97e482d8eb9288c1aa.tar.bz2 sd-mux-edbc2c8e7b8cf87284393a97e482d8eb9288c1aa.zip |
parseArguments: avoid segmentation fault
If an incorrect command line argument is provided poptBadOption() is
called. Freeing the context optCon before this call leads to a
segmentation fault.
If no command line argument is provided we should free the context after
displaying the usage information to avoid a memory leak.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
-rw-r--r-- | src/main.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp index 4c6e917..43b74a8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -709,6 +709,7 @@ int parseArguments(int argc, const char **argv, CCCommand *cmd, int *arg, char * poptSetOtherOptionHelp(optCon, "command"); if (argc < 2) { poptPrintUsage(optCon, stderr, 0); + poptFreeContext(optCon); return EXIT_SUCCESS; } /* Now do options processing, get portname */ @@ -756,17 +757,18 @@ int parseArguments(int argc, const char **argv, CCCommand *cmd, int *arg, char * } } - poptFreeContext(optCon); - if (serial) snprintf(args, argsLen, "%s", serial); free(serial); if (c < -1) { fprintf(stderr, "%s: %s\n", poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(c)); + poptFreeContext(optCon); return EXIT_FAILURE; } + poptFreeContext(optCon); + return EXIT_SUCCESS; } |