From 0ed70d5d1927628033b92a029941cfb23e141c57 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 2 Jul 2022 08:30:52 -0700 Subject: [PATCH] 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`. --- lib/gvpr/gvpr.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) 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); -- 2.40.0