Memory Management
Rules
-
All allocated strings must be freed
boxlite_box_id()->boxlite_free_string()boxlite_list_info()->boxlite_free_string()- Info/metrics JSON ->
boxlite_free_string()
-
Error structs must be freed
CBoxliteError->boxlite_error_free()
-
Results must be freed
CBoxliteExecResult->boxlite_result_free()
- All cleanup functions are NULL-safe
Functions
boxlite_free_string
Free a string allocated by BoxLite.Use this for any string returned by BoxLite API functions such as
boxlite_box_id(), boxlite_list_info(), boxlite_get_info(), boxlite_box_info(), boxlite_runtime_metrics(), and boxlite_box_metrics(). Safe to call with NULL.boxlite_error_free
Free error struct (message only - struct itself is stack-allocated).boxlite_result_free
Free an execution result.boxlite_simple_free
Free a simple box (auto-stops and removes).boxlite_runtime_free
Free a runtime instance.Memory Ownership Summary
JSON Schema Reference
BoxOptions Schema
Required Fields
All BoxOptions JSON must include these fields:Field Reference
RootfsSpec
VolumeSpec
PortSpec
Building JSON in C
Since C has no native JSON support, here are common approaches for constructing BoxOptions JSON:String Concatenation
Using snprintf for Dynamic Values
With Environment Variables
With Volumes and Ports
Thread Safety
Safe Multi-threaded Usage
Callback Threading
Callbacks passed toboxlite_execute are always invoked on the calling thread. This means:
- You do not need to synchronize within the callback itself
- The callback blocks the execution until it returns
- Heavy processing in callbacks will slow down command execution

