Code

object: Ensure that a type's destroy callback is called if init fails.
authorSebastian Harl <sh@tokkee.org>
Sun, 1 Dec 2013 15:55:13 +0000 (16:55 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 1 Dec 2013 15:55:13 +0000 (16:55 +0100)
Else, failed init may leak memory.

src/core/object.c

index 0205ed588f1e58a8afd727a99443c8037add9604..43bb22a8fbf83ee39cb781beab8e34426f9505e9 100644 (file)
@@ -85,6 +85,7 @@ sdb_object_vcreate(const char *name, sdb_type_t type, va_list ap)
        if (! obj)
                return NULL;
        memset(obj, 0, type.size);
+       obj->type = type;
 
        if (name) {
                obj->name = strdup(name);
@@ -103,7 +104,6 @@ sdb_object_vcreate(const char *name, sdb_type_t type, va_list ap)
                }
        }
 
-       obj->type = type;
        obj->ref_cnt = 1;
        return obj;
 } /* sdb_object_vcreate */