X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fobject.c;h=c39faf4aed2c89f684a3e2c0c947b0eba7fe2d18;hp=0205ed588f1e58a8afd727a99443c8037add9604;hb=b75718ea9fe4d6c90f1794e517a0712729553c0c;hpb=73272856dba3b5e49710205601017724fbb6c424 diff --git a/src/core/object.c b/src/core/object.c index 0205ed5..c39faf4 100644 --- a/src/core/object.c +++ b/src/core/object.c @@ -25,6 +25,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#if HAVE_CONFIG_H +# include "config.h" +#endif /* HAVE_CONFIG_H */ + #include "core/object.h" #include @@ -78,13 +82,14 @@ sdb_object_vcreate(const char *name, sdb_type_t type, va_list ap) { sdb_object_t *obj; - if (type.size <= sizeof(sdb_object_t)) + if (type.size < sizeof(sdb_object_t)) return NULL; obj = malloc(type.size); if (! obj) return NULL; memset(obj, 0, type.size); + obj->type = type; if (name) { obj->name = strdup(name); @@ -103,7 +108,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 */ @@ -120,6 +124,14 @@ sdb_object_create(const char *name, sdb_type_t type, ...) return obj; } /* sdb_object_create */ +sdb_object_t * +sdb_object_create_simple(const char *name, size_t size, + void (*destructor)(sdb_object_t *)) +{ + sdb_type_t t = { size, NULL, destructor }; + return sdb_object_create(name, t); +} /* sdb_object_create_simple */ + sdb_object_t * sdb_object_create_wrapper(const char *name, void *data, void (*destructor)(void *)) @@ -137,6 +149,9 @@ sdb_object_deref(sdb_object_t *obj) if (obj->ref_cnt > 0) return; + /* we'd access free'd memory in case ref_cnt < 0 */ + assert(! obj->ref_cnt); + if (obj->type.destroy) obj->type.destroy(obj);