diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2010-09-13 13:46:15 +0300 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2010-09-13 13:49:48 +0300 |
commit | 5573faf301bec875a7b2c9c706ebb2b15cfbde0a (patch) | |
tree | d24d4b3ad8fbf3023a28d9b47ab723aa939a2cbe /lib/rpmdb.c | |
parent | 92c12d1a8ef11106df69b07ca357c560e07e9efd (diff) | |
download | rpm-5573faf301bec875a7b2c9c706ebb2b15cfbde0a.tar.gz rpm-5573faf301bec875a7b2c9c706ebb2b15cfbde0a.tar.bz2 rpm-5573faf301bec875a7b2c9c706ebb2b15cfbde0a.zip |
Rearrange rpmdbInitIterator() a bit for clarity
- Avoid allocating the iterator until we know it's not an error.
Doing the chaining earlier doesn't help anything here as the
cursor used here wasn't linked to the mi at this point, and avoids
having to free up partially initialized structure in case of errors.
- Group the mi initialization to make the actual initialization
stand out from the (unnecessary) zeroing of the calloc()'ed struct.
Diffstat (limited to 'lib/rpmdb.c')
-rw-r--r-- | lib/rpmdb.c | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 41ee92c70..211a28981 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -1949,7 +1949,7 @@ int rpmdbAppendIterator(rpmdbMatchIterator mi, const int * hdrNums, int nHdrNums rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, const void * keyp, size_t keylen) { - rpmdbMatchIterator mi; + rpmdbMatchIterator mi = NULL; dbiIndexSet set = NULL; dbiIndex dbi; void * mi_keyp = NULL; @@ -1970,11 +1970,6 @@ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, if (dbi == NULL) return NULL; - /* Chain cursors for teardown on abnormal exit. */ - mi = xcalloc(1, sizeof(*mi)); - mi->mi_next = rpmmiRock; - rpmmiRock = mi; - /* * Handle label and file name special cases. * Otherwise, retrieve join keys for secondary lookup. @@ -2022,10 +2017,7 @@ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, } if (rc) { /* error/not found */ set = dbiFreeIndexSet(set); - rpmmiRock = mi->mi_next; - mi->mi_next = NULL; - mi = _free(mi); - return NULL; + goto exit; } } @@ -2054,14 +2046,18 @@ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, } } + mi = xcalloc(1, sizeof(*mi)); mi->mi_keyp = mi_keyp; mi->mi_keylen = keylen; - + mi->mi_set = set; mi->mi_db = rpmdbLink(db); mi->mi_rpmtag = rpmtag; + /* Chain cursors for teardown on abnormal exit. */ + mi->mi_next = rpmmiRock; + rpmmiRock = mi; + mi->mi_dbc = NULL; - mi->mi_set = set; mi->mi_setx = 0; mi->mi_h = NULL; mi->mi_sorted = 0; @@ -2076,6 +2072,7 @@ rpmdbMatchIterator rpmdbInitIterator(rpmdb db, rpmTag rpmtag, mi->mi_ts = NULL; mi->mi_hdrchk = NULL; +exit: return mi; } |