Details
Description
Most ForestDB public functions check the input handle for NULL and return an error, typically
FDB_RESULT_INVALID_HANDLE, sometimes FDB_RESULT_INVALID_ARGS. But not all of them do.
I haven't looked through the entire API, just the functions that I use, but these are the functions I've found that will crash if called with a null handle:
fdb_rekey
fdb_begin_transaction
fdb_end_transaction
fdb_compact (and related functions)
fdb_set_log_callback
fdb_rollback [checks for handle_ptr==NULL, but not *handle_ptr==NULL]
fdb_set
fdb_del
fdb_get_byoffset
fdb_get_metaonly_byseq (it does check for NULL, but on the line above it deferences the handle, oops)
This is significant for code that wraps ForestDB for use in a garbage-collected environment. The GC object holding a FDB handle will probably have a close() method to close the handle, which will then set the handle to NULL. But since the object is still alive, it could potentially be called afterwards. If ForestDB is not safe when called with NULL handles, then this adapter layer has to be careful to check the handle for NULL before every ForestDB call.