Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / src / core / store.c
index 8f5cae3..e9e0979 100644 (file)
@@ -418,11 +418,15 @@ sdb_store_attribute(const char *hostname, const char *key, const char *value,
                        /* stored object = */ SDB_ATTRIBUTE, key, last_update,
                        &updated_attr);
 
-       SDB_ATTR(updated_attr)->value = strdup(value);
-       if (! SDB_ATTR(updated_attr)->value) {
-               sdb_object_deref(SDB_OBJ(updated_attr));
-               status = -1;
+       if (status >= 0) {
+               assert(updated_attr);
+               SDB_ATTR(updated_attr)->value = strdup(value);
+               if (! SDB_ATTR(updated_attr)->value) {
+                       sdb_object_deref(SDB_OBJ(updated_attr));
+                       status = -1;
+               }
        }
+
        pthread_rwlock_unlock(&obj_lock);
        return status;
 } /* sdb_store_attribute */
@@ -533,7 +537,7 @@ sdb_store_tojson(sdb_strbuf_t *buf)
                }
 
                sdb_llist_iter_destroy(svc_iter);
-               sdb_strbuf_append(buf, "]}");
+               sdb_strbuf_append(buf, "]},");
        }
 
        sdb_strbuf_append(buf, "]}");