Skip to content

ABI and Memory Ownership

v2rayroot edited this page Jun 14, 2026 · 1 revision

ABI and Memory Ownership

Encoding

All input and output strings use UTF-8 and are null terminated.

Ownership Rule

Every non-null char* returned by V2Root Core is owned by the caller and must be released exactly once with:

void FreeCString(char *value);

Passing null to FreeCString is safe.

Never use free, HeapFree, LocalFree, CoTaskMemFree, or a language runtime allocator on returned pointers.

Null and Empty Values

Result Meaning
Null from Start or Stop Success
Non-null from Start or Stop Allocated error message
Allocated empty string from parser APIs Parse/conversion failure

An empty parser result still needs FreeCString.

Safe C Pattern

char *status = GetStatus();
if (status != NULL) {
    printf("%s\n", status);
    FreeCString(status);
}

Wrapper Requirements

  • Copy the native string before releasing it.
  • Do not expose raw pointers outside the wrapper.
  • Do not unload the library while returned pointers are alive.
  • Use the generated header as the ABI source of truth.

Public Memory API

FreeCString

void FreeCString(char *value);

This is the only supported release function for native strings.

Clone this wiki locally