Skip to content

Commit 7060a38

Browse files
committed
Fix memory leak, use reference for track data.
1 parent 398a48a commit 7060a38

4 files changed

Lines changed: 10 additions & 6 deletions

File tree

libs/server-sdk/include/launchdarkly/server_side/hooks/hook.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,14 +353,14 @@ class TrackSeriesContext {
353353
* @param context The context associated with the track call.
354354
* @param key The event key.
355355
* @param metric_value Optional metric value.
356-
* @param data Optional application-specified data.
356+
* @param data Optional reference to application-specified data.
357357
* @param hook_context Additional context data provided by the caller.
358358
* @param environment_id Optional environment ID.
359359
*/
360360
TrackSeriesContext(Context const& context,
361361
std::string key,
362362
std::optional<double> metric_value,
363-
std::optional<Value> data,
363+
std::optional<std::reference_wrapper<Value const>> data,
364364
HookContext const& hook_context,
365365
std::optional<std::string> environment_id);
366366

@@ -433,7 +433,7 @@ class TrackSeriesContext {
433433
Context const& context_;
434434
std::string key_;
435435
std::optional<double> metric_value_;
436-
std::optional<Value> data_;
436+
std::optional<std::reference_wrapper<Value const>> data_;
437437
HookContext const& hook_context_;
438438
std::optional<std::string> environment_id_;
439439
};

libs/server-sdk/src/bindings/c/sdk.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ LDServerSDK_TrackMetric_WithHookContext(LDServerSDK sdk,
449449
TO_SDK(sdk)->Track(*TO_CONTEXT(context), event_name,
450450
*TO_VALUE(data), metric_value);
451451
}
452+
453+
LDValue_Free(data);
452454
}
453455

454456
LD_EXPORT(void)
@@ -469,6 +471,8 @@ LDServerSDK_TrackData_WithHookContext(LDServerSDK sdk,
469471
TO_SDK(sdk)->Track(*TO_CONTEXT(context), event_name,
470472
*TO_VALUE(data));
471473
}
474+
475+
LDValue_Free(data);
472476
}
473477

474478
LD_EXPORT(bool)

libs/server-sdk/src/client_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ void ClientImpl::TrackInternal(Context const& ctx,
252252
// minimal functional difference.
253253
if (!config_.Hooks().empty()) {
254254
hooks::TrackSeriesContext series_context(ctx, event_name, metric_value,
255-
data, hook_context, std::nullopt);
255+
data, hook_context, std::nullopt);
256256
hooks::ExecuteAfterTrack(config_.Hooks(), series_context, logger_);
257257
}
258258

libs/server-sdk/src/hooks/hook.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ TrackSeriesContext::TrackSeriesContext(
146146
Context const& context,
147147
std::string key,
148148
std::optional<double> metric_value,
149-
std::optional<Value> data,
149+
std::optional<std::reference_wrapper<Value const>> data,
150150
HookContext const& hook_context,
151151
std::optional<std::string> environment_id)
152152
: context_(context),
153153
key_(std::move(key)),
154154
metric_value_(metric_value),
155-
data_(std::move(data)),
155+
data_(data),
156156
hook_context_(hook_context),
157157
environment_id_(std::move(environment_id)) {}
158158

0 commit comments

Comments
 (0)