Fix dangling databases from iterators (ticket #820)
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 15 Apr 2011 07:11:41 +0000 (10:11 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 15 Apr 2011 07:11:41 +0000 (10:11 +0300)
- Call rpmdbClose() instead of rpmdbUnlink() on iterator free to
  actually close the db when refcount goes to zero. This
  fixes the situation where a caller closes a database handle
  while iterators are active: the iterators stay usable and close
  the db when the last one exits.

lib/rpmdb.c

index 1ff2f29..cf99c56 100644 (file)
@@ -1276,8 +1276,7 @@ rpmdbMatchIterator rpmdbFreeIterator(rpmdbMatchIterator mi)
 
     mi->mi_set = dbiFreeIndexSet(mi->mi_set);
     mi->mi_keyp = _free(mi->mi_keyp);
-    /* XXX rpmdbUnlink() should be rpmdbFree() but no such call exists... */
-    mi->mi_db = rpmdbUnlink(mi->mi_db);
+    rpmdbClose(mi->mi_db);
     mi->mi_ts = rpmtsFree(mi->mi_ts);
 
     mi = _free(mi);
@@ -2279,7 +2278,7 @@ rpmdbIndexIterator rpmdbIndexIteratorFree(rpmdbIndexIterator ii)
         xx = dbiCclose(ii->ii_dbi, ii->ii_dbc, 0);
     ii->ii_dbc = NULL;
     ii->ii_dbi = NULL;
-    ii->ii_db = rpmdbUnlink(ii->ii_db);
+    rpmdbClose(ii->ii_db);
     ii->ii_set = dbiFreeIndexSet(ii->ii_set);
 
     ii = _free(ii);