What problem does this solve?
I'm compiling codebase-memory-mcp as a DLL to call it from C# (P/Invoke), and three public API functions document caller-owned memory but export no matching free function — unlike the rest of the API:
cbm_store_fetch_call_edges (store.h:471) — "caller frees both" — two int64_t* arrays
cbm_leiden / cbm_louvain (store.h:843, 847) — "the caller frees it" — one cbm_louvain_result_t* array
cbm_layout_to_json (layout3d.h:72) — "Caller must free()." — one char*
The rest of the API does follow a paired-free pattern: cbm_store_find_nodes→cbm_store_free_nodes, cbm_layout_compute→cbm_layout_free, cbm_store_get_schema→cbm_store_schema_free, etc. From C, a bare free() works fine because of static linking — but from C# there's no way to invoke the DLL's internal free() unless it's exported by name.
Proposed solution
Export a paired free for each of the three, following the existing pattern. I can implement this. Two questions on approach before I send the PR:
- 3 specific free functions (
cbm_store_free_call_edges, cbm_leiden_free, cbm_layout_free_json), or a generic cbm_free(void*)?
- One PR for all 3, or one per function?
Alternatives considered
None that hold up across an FFI boundary — a foreign caller has no way to reach the DLL's internal free() without an exported symbol.
Confirmations
What problem does this solve?
I'm compiling
codebase-memory-mcpas a DLL to call it from C# (P/Invoke), and three public API functions document caller-owned memory but export no matching free function — unlike the rest of the API:cbm_store_fetch_call_edges(store.h:471) — "caller frees both" — twoint64_t*arrayscbm_leiden/cbm_louvain(store.h:843, 847) — "the caller frees it" — onecbm_louvain_result_t*arraycbm_layout_to_json(layout3d.h:72) — "Caller must free()." — onechar*The rest of the API does follow a paired-free pattern:
cbm_store_find_nodes→cbm_store_free_nodes,cbm_layout_compute→cbm_layout_free,cbm_store_get_schema→cbm_store_schema_free, etc. From C, a barefree()works fine because of static linking — but from C# there's no way to invoke the DLL's internalfree()unless it's exported by name.Proposed solution
Export a paired free for each of the three, following the existing pattern. I can implement this. Two questions on approach before I send the PR:
cbm_store_free_call_edges,cbm_leiden_free,cbm_layout_free_json), or a genericcbm_free(void*)?Alternatives considered
None that hold up across an FFI boundary — a foreign caller has no way to reach the DLL's internal
free()without an exported symbol.Confirmations