Skip to content

Commit cdc0f43

Browse files
committed
doc: clarify lifetime and ownership rules for C hook callback parameters
Strengthen the documentation in hook.h to make it explicit that all SDK-provided pointers (series_context, data, detail, etc.) must not be retained, cached, or stored beyond the scope of the callback invocation, and that any data needed outside the callback must be copied.
1 parent b741911 commit cdc0f43

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

  • libs/server-sdk/include/launchdarkly/server_side/bindings/c

libs/server-sdk/include/launchdarkly/server_side/bindings/c/hook.h

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@
1010
* - The function pointers and UserData pointer are copied when the hook is
1111
* registered with the config builder
1212
* - UserData lifetime must extend for the entire lifetime of the SDK client
13-
* - All context parameters passed to callbacks are temporary - valid only
14-
* during the callback execution
13+
*
14+
* WARNING: All pointers passed to callbacks by the SDK (series_context, data,
15+
* detail, etc.) are owned by the SDK and may be freed after the callback
16+
* returns. You MUST NOT retain, cache, or store these pointers, or any
17+
* references to data within them, beyond the scope of the callback invocation.
18+
* Any data needed outside the duration of a callback must be copied during the
19+
* callback. Accessing a stored pointer or reference after the callback has
20+
* returned results in undefined behavior.
21+
*
1522
* - EvaluationSeriesData returned from callbacks transfers ownership to the SDK
1623
*/
1724
// NOLINTBEGIN(modernize-use-using)
@@ -49,7 +56,8 @@ typedef struct p_LDServerSDKTrackSeriesContext* LDServerSDKTrackSeriesContext;
4956
*
5057
* LIFETIME:
5158
* - series_context: Valid only during callback execution - do not store
52-
* - data: Ownership transfers to SDK
59+
* - data: Valid only during callback execution - do not store. Ownership of
60+
* the returned value transfers to the SDK.
5361
* - user_data: Managed by caller - must remain valid for SDK lifetime
5462
*/
5563
typedef LDServerSDKEvaluationSeriesData (*LDServerSDKHook_BeforeEvaluation)(
@@ -77,10 +85,11 @@ typedef LDServerSDKEvaluationSeriesData (*LDServerSDKHook_BeforeEvaluation)(
7785
* If NULL is returned, an empty data object will be created.
7886
*
7987
* LIFETIME:
80-
* - series_context: Valid only during callback execution
81-
* - data: Ownership transfers to SDK
82-
* - detail: Valid only during callback execution
83-
* - user_data: Managed by caller
88+
* - series_context: Valid only during callback execution - do not store
89+
* - data: Valid only during callback execution - do not store. Ownership of
90+
* the returned value transfers to the SDK.
91+
* - detail: Valid only during callback execution - do not store
92+
* - user_data: Managed by caller - must remain valid for SDK lifetime
8493
*/
8594
typedef LDServerSDKEvaluationSeriesData (*LDServerSDKHook_AfterEvaluation)(
8695
LDServerSDKEvaluationSeriesContext series_context,
@@ -102,8 +111,8 @@ typedef LDServerSDKEvaluationSeriesData (*LDServerSDKHook_AfterEvaluation)(
102111
* RETURNS: void (no data is passed between track stages)
103112
*
104113
* LIFETIME:
105-
* - series_context: Valid only during callback execution
106-
* - user_data: Managed by caller
114+
* - series_context: Valid only during callback execution - do not store
115+
* - user_data: Managed by caller - must remain valid for SDK lifetime
107116
*/
108117
typedef void (*LDServerSDKHook_AfterTrack)(LDServerSDKTrackSeriesContext series_context,
109118
void* user_data);

0 commit comments

Comments
 (0)