refactored load_db function

Wed, 13 Jul 2016 17:10:00 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 13 Jul 2016 17:10:00 +0200
changeset 248
99574ca1c253
parent 247
3020d1b5e7bd
child 249
50fb9c9f6671

refactored load_db function

dav/db.c file | annotate | diff | comparison | revisions
dav/version.h file | annotate | diff | comparison | revisions
--- a/dav/db.c	Wed Jul 13 16:27:06 2016 +0200
+++ b/dav/db.c	Wed Jul 13 17:10:00 2016 +0200
@@ -52,16 +52,16 @@
     free(dav_dir);
     
     SyncDatabase *db = malloc(sizeof(SyncDatabase));
+    db->resources = ucx_map_new(2048);
+    db->conflict = ucx_map_new(16);
+    
     xmlTextReaderPtr reader = xmlReaderForFile(db_file, NULL, 0);
     if(!reader) {
         xmlDoc *doc =  doc = xmlNewDoc(BAD_CAST "1.0");
         xmlNode *root = xmlNewNode(NULL, BAD_CAST "directory");
         xmlDocSetRootElement(doc, root);
-        if(xmlSaveFormatFileEnc(db_file, doc, "UTF-8", 1) != -1) {
-            db->resources = ucx_map_new(2048);
-            db->conflict = ucx_map_new(16);
-        } else {
-            free(db);
+        if(!xmlSaveFormatFileEnc(db_file, doc, "UTF-8", 1) != -1) {
+            destroy_db(db);
             db = NULL;
         }
         xmlFreeDoc(doc);
@@ -70,8 +70,6 @@
     }
     free(db_file);
     
-    db->resources = ucx_map_new(2048);
-    db->conflict = ucx_map_new(16);
     int error = 0;
     while(xmlTextReaderRead(reader)) {
         int type = xmlTextReaderNodeType(reader);
@@ -100,7 +98,7 @@
     
     xmlFreeTextReader(reader);
     if(error) {
-        // TODO: free resources and map
+        destroy_db(db);
         return NULL;
     } else {
         return db;
--- a/dav/version.h	Wed Jul 13 16:27:06 2016 +0200
+++ b/dav/version.h	Wed Jul 13 17:10:00 2016 +0200
@@ -29,7 +29,7 @@
 #ifndef VERSION_H
 #define VERSION_H
 
-#define DAV_VERSION "1.0.0 RC2"
+#define DAV_VERSION "1.0.0 RC3"
 
 #endif /* VERSION_H */
 

mercurial