From 12c69b1075ab1cca55cc713758a860ade9eef0b4 Mon Sep 17 00:00:00 2001 From: jbj Date: Wed, 24 Feb 1999 23:55:00 +0000 Subject: [PATCH] Memory leaks. CVS patchset: 2833 CVS date: 1999/02/24 23:55:00 --- install.c | 22 ++++++++++++++-------- lib/depends.c | 9 +++++++-- lib/transaction.c | 23 ++++++++++++++++++++++- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/install.c b/install.c index 27ca7e1..3bf5438 100644 --- a/install.c +++ b/install.c @@ -98,7 +98,6 @@ int doInstall(const char * rootdir, const char ** argv, int transFlags, int stopInstall = 0; size_t nb; int notifyFlags = interfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 ); - rpmProblemSet probs, finalProbs; int dbIsOpen = 0; const char ** sourcePackages; @@ -238,37 +237,44 @@ int doInstall(const char * rootdir, const char ** argv, int transFlags, } if (numBinaryPackages && !(interfaceFlags & INSTALL_NOORDER)) { - if (rpmdepOrder(rpmdep, (void ***) &packages)) { + if (rpmdepOrder(rpmdep, NULL)) { numFailed = numPackages; stopInstall = 1; } } if (numBinaryPackages && !stopInstall) { + rpmProblemSet probs = NULL; +; rpmMessage(RPMMESS_DEBUG, _("installing binary packages\n")); rc = rpmRunTransactions(rpmdep, showProgress, (void *) notifyFlags, NULL, &probs, transFlags); if (rc < 0) { numFailed += numPackages; } else if (rc) { + rpmProblemSet finalProbs = NULL; rpmProblemSetFilter(probs, probFilter); rc = rpmRunTransactions(rpmdep, showProgress, (void *) notifyFlags, probs, &finalProbs, transFlags); rpmProblemSetFree(probs); + probs = NULL; if (rc < 0) { numFailed += numBinaryPackages; } else if (rc) { numFailed += rc; - for (i = 0; i < finalProbs->numProblems; i++) - if (!finalProbs->probs[i].ignoreProblem) - rpmMessage(RPMMESS_ERROR, "%s\n", - rpmProblemString(finalProbs->probs[i])); - - rpmProblemSetFree(finalProbs); + for (i = 0; i < finalProbs->numProblems; i++) { + if (!finalProbs->probs[i].ignoreProblem) { + char *msg = rpmProblemString(finalProbs->probs[i]); + rpmMessage(RPMMESS_ERROR, "%s\n", msg); + free(msg); + } + } } + if (finalProbs) rpmProblemSetFree(finalProbs); } + if (probs) rpmProblemSetFree(probs); } if (numBinaryPackages) rpmtransFree(rpmdep); diff --git a/lib/depends.c b/lib/depends.c index 67ad6dc..4aae3f8 100644 --- a/lib/depends.c +++ b/lib/depends.c @@ -47,7 +47,8 @@ static void alCreate(struct availableList * al) { static void alFreeIndex(struct availableList * al) { if (al->index.size) { - free(al->index.index); + if (al->index.index) + free(al->index.index); al->index.index = NULL; al->index.size = 0; } @@ -571,6 +572,7 @@ static int checkDependentConflicts(rpmTransactionSet rpmdep, } rc = checkPackageSet(rpmdep, psp, package, &matches); + dbiFreeIndexRecord(matches); return rc; } @@ -903,7 +905,10 @@ int rpmdepOrder(rpmTransactionSet rpmdep, void *** keysListPtr) { } order[orderNum] = NULL; - *keysListPtr = order; + if (keysListPtr != NULL) + *keysListPtr = order; + else + free(order); return 0; } diff --git a/lib/transaction.c b/lib/transaction.c index e931ee5..5ba028a 100644 --- a/lib/transaction.c +++ b/lib/transaction.c @@ -174,6 +174,7 @@ NOTIFY((NULL, RPMCALLBACK_TRANS_START, 3, al->size, NULL, notifyData)); continue; } +/* XXX FIXME: There is a memory leak here ... */ fi->actions = calloc(sizeof(*fi->actions), fi->fc); fi->h = hdrs[alp - al->list] = relocateFileList(alp, probs, alp->h, fi->actions); @@ -232,7 +233,12 @@ NOTIFY((fi->h, RPMCALLBACK_TRANS_PROGRESS, i, ts->numRemovedPackages, headerGetEntryMinMemory(fi->h, RPMTAG_FILESTATES, NULL, (void *) &fi->fstates, NULL); +/* XXX FIXME: ... or there is a memory leak here ... */ /* Note that as FA_UNKNOWN = 0, this does the right thing */ + if (fi->actions) { + free(fi->actions); + fi->actions = NULL; + } fi->actions = calloc(sizeof(*fi->actions), fi->fc); fi->fps = alloca(fi->fc * sizeof(*fi->fps)); } @@ -281,6 +287,7 @@ NOTIFY((NULL, RPMCALLBACK_TRANS_PROGRESS, (fi - flList), flEntries, shared->otherFileNum = matches[i].recs[j].fileNumber; shared++; } + dbiFreeIndexRecord(matches[i]); } shared->otherPkg = -1; free(matches); @@ -346,6 +353,7 @@ NOTIFY((NULL, RPMCALLBACK_TRANS_START, 8, al->size, NULL, notifyData)); if (fi->fc) { headerFree(hdrs[alp - al->list]); free(fi->actions); + fi->actions = NULL; } } @@ -393,8 +401,10 @@ NOTIFY((NULL, RPMCALLBACK_TRANS_START, 9, al->size, NULL, notifyData)); headerFree(hdrs[alp - al->list]); - if (fi->fc) + if (fi->fc) { free(fi->actions); + fi->actions = NULL; + } if (!alp->fd && fd) notify(fi->h, RPMCALLBACK_INST_CLOSE_FILE, 0, 0, alp->key, @@ -419,6 +429,17 @@ NOTIFY((fi->h, RPMCALLBACK_UNINST_PROGRESS, i, ts->numRemovedPackages, NOTIFY((NULL, RPMCALLBACK_UNINST_STOP, 0, ts->numRemovedPackages, NULL, notifyData)); +/* XXX FIXME: ... or possibly there is a memory leak here. */ + if (fi->actions) { + free(fi->actions); + fi->actions = NULL; + } +/* XXX FIXME: This smells like a memory leak. */ + if (fi->replaced) { + free(fi->replaced); + fi->replaced = NULL; + } + if (ourrc) return -1; else -- 2.7.4