From: Matthew Fernandez Date: Sat, 2 Jul 2022 15:30:52 +0000 (-0700) Subject: gvpr: simplify 'freeOpts' by passing by value X-Git-Tag: 5.0.0~5^2~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0ed70d5d1927628033b92a029941cfb23e141c57;p=graphviz gvpr: simplify 'freeOpts' by passing by value This also removes the conditional on `argc` in this function. The contained loop is a no-op when `argc` is 0 and in this case `argv` is NULL, which it is well defined to `free`. --- diff --git a/lib/gvpr/gvpr.c b/lib/gvpr/gvpr.c index 82ba2e129..68032edb6 100644 --- a/lib/gvpr/gvpr.c +++ b/lib/gvpr/gvpr.c @@ -15,7 +15,6 @@ * Written by Emden Gansner */ -#include #include #include "builddate.h" #include @@ -359,21 +358,15 @@ doFlags(char* arg, int argi, int argc, char** argv, options* opts) return argi; } -static void -freeOpts (options* opts) -{ - int i; - assert(opts != NULL); - if (opts->outFile != sfstdout) - sfclose (opts->outFile); - free (opts->inFiles); - if (opts->useFile) - free (opts->program); - if (opts->argc) { - for (i = 0; i < opts->argc; i++) - free (opts->argv[i]); - free (opts->argv); - } +static void freeOpts(options opts) { + if (opts.outFile != sfstdout) + sfclose(opts.outFile); + free(opts.inFiles); + if (opts.useFile) + free(opts.program); + for (int i = 0; i < opts.argc; i++) + free(opts.argv[i]); + free(opts.argv); } /* scanArgs: @@ -1082,7 +1075,7 @@ int gvpr (int argc, char *argv[], gvpropts * uopts) freeCompileProg (xprog); closeGPRState(state); if (ing) closeIngraph (ing); - freeOpts(&opts); + freeOpts(opts); if (uopts) { if (uopts->out) sfdisc (sfstdout, 0);