Description
The Property() function in explain.go creates two C.CString allocations that are never freed, causing a memory leak.
Current Code
func (e Explainer) Property(k, v string) {
C.ExplainPropertyText(C.CString(k), C.CString(v), e.ES)
}
Problem
C.CString() allocates memory on the C heap which must be explicitly freed with C.free(). The current code passes the result directly to ExplainPropertyText without storing it, making it impossible to free.
Impact
- Severity: Low
- Frequency: Only during EXPLAIN queries (development/debugging)
- Memory leaked: ~50-100 bytes per EXPLAIN property
Proposed Fix
Store CString results in variables and free them after use:
func (e Explainer) Property(k, v string) {
ck := C.CString(k)
cv := C.CString(v)
defer C.free(unsafe.Pointer(ck))
defer C.free(unsafe.Pointer(cv))
C.ExplainPropertyText(ck, cv, e.ES)
}
Using defer is appropriate here since EXPLAIN is not a hot path.
Description
The
Property()function inexplain.gocreates twoC.CStringallocations that are never freed, causing a memory leak.Current Code
Problem
C.CString()allocates memory on the C heap which must be explicitly freed withC.free(). The current code passes the result directly toExplainPropertyTextwithout storing it, making it impossible to free.Impact
Proposed Fix
Store CString results in variables and free them after use:
Using
deferis appropriate here since EXPLAIN is not a hot path.