diff --git a/lib/rpmdb.c b/lib/rpmdb.c index d38b8fe3e0..2dd368432d 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -315,7 +315,7 @@ int rpmdbCheckTerminate(int terminate) sigset_t newMask, oldMask; static int terminating = 0; - if (terminating) return 0; + if (terminating) return terminating; (void) sigfillset(&newMask); /* block all signals */ (void) sigprocmask(SIG_BLOCK, &newMask, &oldMask); @@ -454,6 +454,12 @@ int rpmdbClose(rpmdb db) if (db == NULL) goto exit; + prev = &rpmdbRock; + while ((next = *prev) != NULL && next != db) + prev = &next->db_next; + if (!next) + goto exit; + (void) rpmdbUnlink(db); if (db->nrefs > 0) @@ -474,9 +480,6 @@ int rpmdbClose(rpmdb db) db->db_indexes = _free(db->db_indexes); db->db_descr = _free(db->db_descr); - prev = &rpmdbRock; - while ((next = *prev) != NULL && next != db) - prev = &next->db_next; if (next) { *prev = next->db_next; next->db_next = NULL; @@ -1085,7 +1088,8 @@ rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi) if (next) { *prev = next->mi_next; next->mi_next = NULL; - } + } else + return NULL; pkgdbOpen(mi->mi_db, 0, &dbi); @@ -2085,7 +2089,8 @@ rpmdbIndexIterator rpmdbIndexIteratorFree(rpmdbIndexIterator ii) if (next) { *prev = next->ii_next; next->ii_next = NULL; - } + } else + return NULL; ii->ii_dbc = dbiCursorFree(ii->ii_dbi, ii->ii_dbc); ii->ii_dbi = NULL;