diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2009-09-14 09:48:49 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2009-09-14 09:48:49 +0300 |
commit | cb2bd766ded51790353ae667aedbfeee0e9494f9 (patch) | |
tree | 0ccf4b8ee011d7f56ace9432d512fb83475742eb /build/parsePrep.c | |
parent | 154462928eb6c391e2505ce7bc7354b1eb215f3c (diff) | |
download | rpm-cb2bd766ded51790353ae667aedbfeee0e9494f9.tar.gz rpm-cb2bd766ded51790353ae667aedbfeee0e9494f9.tar.bz2 rpm-cb2bd766ded51790353ae667aedbfeee0e9494f9.zip |
Single point of exit for doSetupMacro() to clean up freeing allocations
Diffstat (limited to 'build/parsePrep.c')
-rw-r--r-- | build/parsePrep.c | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/build/parsePrep.c b/build/parsePrep.c index 44d605877..5d94de083 100644 --- a/build/parsePrep.c +++ b/build/parsePrep.c @@ -243,14 +243,15 @@ static char *doUntar(rpmSpec spec, uint32_t c, int quietly) static int doSetupMacro(rpmSpec spec, const char *line) { char *buf = NULL; - StringBuf before; - StringBuf after; - poptContext optCon; + StringBuf before = newStringBuf(); + StringBuf after = newStringBuf(); + poptContext optCon = NULL; int argc; - const char ** argv; + const char ** argv = NULL; int arg; const char * optArg; - int rc; + int xx; + rpmRC rc = RPMRC_FAIL; uint32_t num; int leaveDirs = 0, skipDefaultAction = 0; int createDir = 0, quietly = 0; @@ -266,15 +267,11 @@ static int doSetupMacro(rpmSpec spec, const char *line) { 0, 0, 0, 0, 0, NULL, NULL} }; - if ((rc = poptParseArgvString(line, &argc, &argv))) { - rpmlog(RPMLOG_ERR, _("Error parsing %%setup: %s\n"), - poptStrerror(rc)); - return RPMRC_FAIL; + if ((xx = poptParseArgvString(line, &argc, &argv))) { + rpmlog(RPMLOG_ERR, _("Error parsing %%setup: %s\n"), poptStrerror(xx)); + goto exit; } - before = newStringBuf(); - after = newStringBuf(); - optCon = poptGetContext(NULL, argc, argv, optionsTable, 0); while ((arg = poptGetNextOpt(optCon)) > 0) { optArg = poptGetOptArg(optCon); @@ -284,16 +281,12 @@ static int doSetupMacro(rpmSpec spec, const char *line) if (parseUnsignedNum(optArg, &num)) { rpmlog(RPMLOG_ERR, _("line %d: Bad arg to %%setup: %s\n"), spec->lineNum, (optArg ? optArg : "???")); - before = freeStringBuf(before); - after = freeStringBuf(after); - optCon = poptFreeContext(optCon); - argv = _free(argv); - return RPMRC_FAIL; + goto exit; } { char *chptr = doUntar(spec, num, quietly); if (chptr == NULL) - return RPMRC_FAIL; + goto exit; appendLineStringBuf((arg == 'a' ? after : before), chptr); free(chptr); @@ -305,11 +298,7 @@ static int doSetupMacro(rpmSpec spec, const char *line) spec->lineNum, poptBadOption(optCon, POPT_BADOPTION_NOALIAS), poptStrerror(arg)); - before = freeStringBuf(before); - after = freeStringBuf(after); - optCon = poptFreeContext(optCon); - argv = _free(argv); - return RPMRC_FAIL; + goto exit; } if (dirName) { @@ -321,9 +310,6 @@ static int doSetupMacro(rpmSpec spec, const char *line) } addMacro(spec->macros, "buildsubdir", NULL, spec->buildSubdir, RMIL_SPEC); - optCon = poptFreeContext(optCon); - argv = _free(argv); - /* cd to the build dir */ { char * buildDir = rpmGenPath(spec->rootDir, "%{_builddir}", ""); @@ -352,13 +338,12 @@ static int doSetupMacro(rpmSpec spec, const char *line) if (!createDir && !skipDefaultAction) { char *chptr = doUntar(spec, 0, quietly); if (!chptr) - return RPMRC_FAIL; + goto exit; appendLineStringBuf(spec->prep, chptr); free(chptr); } appendStringBuf(spec->prep, getStringBuf(before)); - before = freeStringBuf(before); if (!createDir) { rasprintf(&buf, "cd '%s'", spec->buildSubdir); @@ -369,13 +354,12 @@ static int doSetupMacro(rpmSpec spec, const char *line) if (createDir && !skipDefaultAction) { char *chptr = doUntar(spec, 0, quietly); if (chptr == NULL) - return RPMRC_FAIL; + goto exit; appendLineStringBuf(spec->prep, chptr); free(chptr); } appendStringBuf(spec->prep, getStringBuf(after)); - after = freeStringBuf(after); /* Fix the permissions of the setup build tree */ { char *fix = rpmExpand("%{_fixperms} .", NULL); @@ -384,8 +368,15 @@ static int doSetupMacro(rpmSpec spec, const char *line) } free(fix); } - - return RPMRC_OK; + rc = RPMRC_OK; + +exit: + freeStringBuf(before); + freeStringBuf(after); + poptFreeContext(optCon); + free(argv); + + return rc; } /** |