From b0338657a85ae9e1c77d58b42363d23dde012550 Mon Sep 17 00:00:00 2001 From: Panu Matilainen Date: Mon, 13 Sep 2010 14:16:44 +0300 Subject: [PATCH] Rearrange newRpmdb() a bit for clarity - Avoid allocating the structure until we know its ok. --- lib/rpmdb.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/rpmdb.c b/lib/rpmdb.c index 6b09e70..ca65249 100644 --- a/lib/rpmdb.c +++ b/lib/rpmdb.c @@ -658,7 +658,16 @@ int rpmdbSync(rpmdb db) static rpmdb newRpmdb(const char * root, const char * home, int mode, int perms, int flags) { - rpmdb db = xcalloc(sizeof(*db), 1); + rpmdb db = NULL; + char * db_home = rpmGetPath((home && *home) ? home : "%{_dbpath}", NULL); + + if (!(db_home && db_home[0] != '%')) { + rpmlog(RPMLOG_ERR, _("no dbpath has been set\n")); + free(db_home); + return NULL; + } + + db = xcalloc(sizeof(*db), 1); if (!(perms & 0600)) perms = 0644; /* XXX sanity */ @@ -666,13 +675,7 @@ static rpmdb newRpmdb(const char * root, const char * home, db->db_perms = (perms >= 0) ? perms : 0644; db->db_flags = (flags >= 0) ? flags : 0; - db->db_home = rpmGetPath( (home && *home ? home : "%{_dbpath}"), NULL); - if (!(db->db_home && db->db_home[0] != '%')) { - rpmlog(RPMLOG_ERR, _("no dbpath has been set\n")); - db->db_home = _free(db->db_home); - db = _free(db); - return NULL; - } + db->db_home = db_home; db->db_root = rpmGetPath((root && *root) ? root : "/", NULL); db->db_fullpath = rpmGenPath(db->db_root, db->db_home, NULL); /* XXX remove environment after chrooted operations, for now... */ -- 2.7.4