error detection and memory leaks in c example

main
Haneef Mubarak 10 years ago
parent c6f31a2893
commit 91c58752fa
  1. 12
      examples/simple_example.c

@ -20,24 +20,28 @@ int main (int argc, char **argv) {
rocksdb_options_set_create_if_missing (options, 1);
// open DB
char *err;
char *err = NULL;
db = rocksdb_open (options, DBPath, &err);
// assert (!err);
assert (!err);
// Put key-value
rocksdb_writeoptions_t *writeoptions = rocksdb_writeoptions_create ();
const char key[] = "key";
char *value = "value";
rocksdb_put (db, writeoptions, key, strlen (key), value, strlen (value), &err);
// assert (!err);
assert (!err);
// Get value
rocksdb_readoptions_t *readoptions = rocksdb_readoptions_create ();
size_t len;
value = rocksdb_get (db, readoptions, key, strlen (key), &len, &err);
// assert (!err);
assert (!err);
assert (strcmp (value, "value") == 0);
free (value);
// cleanup
rocksdb_writeoptions_destroy (writeoptions);
rocksdb_readoptions_destroy (readoptions);
rocksdb_options_destroy (options);
rocksdb_close (db);
return 0;

Loading…
Cancel
Save