X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=datastore.c;h=bb59fd587cbe5cf3d5cdd5a8e7025d3378ff3e43;hb=33247d6acf94bb9119ba7e1a8239b474bdcfa430;hp=443ab1539d96c0bbf920f8da369488f9905cd684;hpb=6b5e3ceefcdee5e942b9cbff5c697016dacee774;p=libsigrok.git diff --git a/datastore.c b/datastore.c index 443ab153..bb59fd58 100644 --- a/datastore.c +++ b/datastore.c @@ -25,11 +25,19 @@ static gpointer new_chunk(struct datastore **ds); +/* TODO: Return int as error status, and the struct as param. */ struct datastore *datastore_new(int unitsize) { struct datastore *ds; - ds = g_malloc(sizeof(struct datastore)); + if (unitsize <= 0) + // return SIGROK_ERR; + return NULL; /* FIXME */ + + if (!(ds = g_malloc(sizeof(struct datastore)))) + // return SIGROK_ERR_MALLOC; + return NULL; /* FIXME */ + ds->ds_unitsize = unitsize; ds->num_units = 0; ds->chunklist = NULL; @@ -37,14 +45,19 @@ struct datastore *datastore_new(int unitsize) return ds; } -void datastore_destroy(struct datastore *ds) +int datastore_destroy(struct datastore *ds) { GSList *chunk; + if (!ds) + return SIGROK_ERR; + for (chunk = ds->chunklist; chunk; chunk = chunk->next) g_free(chunk->data); g_slist_free(ds->chunklist); g_free(ds); + + return SIGROK_OK; } void datastore_put(struct datastore *ds, void *data, unsigned int length, @@ -93,7 +106,9 @@ static gpointer new_chunk(struct datastore **ds) { gpointer chunk; - chunk = g_malloc(DATASTORE_CHUNKSIZE * (*ds)->ds_unitsize); + if (!(chunk = malloc(DATASTORE_CHUNKSIZE * (*ds)->ds_unitsize))) + return NULL; + (*ds)->chunklist = g_slist_append((*ds)->chunklist, chunk); return chunk;