Code

store: Don't try to update non-existent attributes.
authorSebastian Harl <sh@tokkee.org>
Sat, 7 Dec 2013 14:43:06 +0000 (15:43 +0100)
committerSebastian Harl <sh@tokkee.org>
Sat, 7 Dec 2013 14:43:06 +0000 (15:43 +0100)
src/core/store.c

index 587c527a5185699efe18d104d65f499c12801145..95aaafad9a46b370c17d0aec0e885bbb66843e1f 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 */