One complicated way to write xstrdup() .. pff
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 16 Sep 2009 09:27:12 +0000 (12:27 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 16 Sep 2009 12:47:10 +0000 (15:47 +0300)
- sqlite backend uses dbi subfile for table name, leave it alone although
  it is the same as the file name...
- allocate + free both file and table name separately

lib/backend/sqlite.c

index 4c1262c..a47c569 100644 (file)
@@ -772,6 +772,7 @@ enterChroot(dbi);
 
        dbi->dbi_stats = _free(dbi->dbi_stats);
        dbi->dbi_file = _free(dbi->dbi_file);
+       dbi->dbi_subfile = _free(dbi->dbi_subfile);
        dbi->dbi_db = _free(dbi->dbi_db);
 
 leaveChroot(dbi);
@@ -801,7 +802,6 @@ static int sql_open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip)
     const char * sql_errcode;
     dbiIndex dbi;
     SQL_DB * sqldb;
-    size_t len;
     int rc = 0;
     int xx;
     
@@ -831,15 +831,8 @@ enterChroot(dbi);
      * Make a copy of the tagName result..
      * use this for the filename and table name
      */
-    {  
-      char * t;
-      len = strlen(dbfile);
-      t = xcalloc(len + 1, sizeof(*t));
-      (void) stpcpy( t, dbfile );
-      dbi->dbi_file = t;
-/* WRONG */
-      dbi->dbi_subfile = t;
-    }
+    dbi->dbi_file = xstrdup(dbfile);
+    dbi->dbi_subfile = xstrdup(dbfile);
 
     dbi->dbi_mode=O_RDWR;