Details
-
Improvement
-
Resolution: Fixed
-
Minor
-
None
-
Security Level: Public
-
None
Description
In the CouchStore API, memory management of DocInfo structs is inconsistent. Sometimes the struct must be allocated and managed by the client (e.g. when calling couchstore_save_document), other times it's allocated and returned by CouchStore and must be freed using a special couchstore_free_docinfo call (e.g. couchstore_docinfo_by_id).
It seems to happen fairly often in writing client code that you need to hang onto a DocInfo*, but sometimes that struct was allocated by CouchStore and sometimes by the app. This then requires keeping a flag alongside it that remembers who allocated it. Making mistakes can lead to crashes (Dustin has complained about this to me.)
I propose we add a new call couchstore_alloc_docinfo that allocates a DocInfo struct the same way that CouchStore does internally. The client can then call this when it needs to allocate its own DocInfos, and not have two different kinds of freeing to worry about.