Skip to content

Commit 5df15bd

Browse files
christophebedard-apexaiAlberto Soragna
authored andcommitted
Fix memory leak in tracetools::get_symbol() (ros2#2104)
Signed-off-by: Christophe Bedard <[email protected]>
1 parent e6ad86b commit 5df15bd

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

rclcpp/include/rclcpp/any_service_callback.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,14 @@ class AnyServiceCallback
191191
#ifndef TRACETOOLS_DISABLED
192192
std::visit(
193193
[this](auto && arg) {
194-
TRACEPOINT(
195-
rclcpp_callback_register,
196-
static_cast<const void *>(this),
197-
tracetools::get_symbol(arg));
194+
if (TRACEPOINT_ENABLED(rclcpp_callback_register)) {
195+
char * symbol = tracetools::get_symbol(arg);
196+
DO_TRACEPOINT(
197+
rclcpp_callback_register,
198+
static_cast<const void *>(this),
199+
symbol);
200+
std::free(symbol);
201+
}
198202
}, callback_);
199203
#endif // TRACETOOLS_DISABLED
200204
}

rclcpp/include/rclcpp/any_subscription_callback.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,14 @@ class AnySubscriptionCallback
959959
#ifndef TRACETOOLS_DISABLED
960960
std::visit(
961961
[this](auto && callback) {
962-
TRACEPOINT(
963-
rclcpp_callback_register,
964-
static_cast<const void *>(this),
965-
tracetools::get_symbol(callback));
962+
if (TRACEPOINT_ENABLED(rclcpp_callback_register)) {
963+
char * symbol = tracetools::get_symbol(callback);
964+
DO_TRACEPOINT(
965+
rclcpp_callback_register,
966+
static_cast<const void *>(this),
967+
symbol);
968+
std::free(symbol);
969+
}
966970
}, callback_variant_);
967971
#endif // TRACETOOLS_DISABLED
968972
}

rclcpp/include/rclcpp/timer.hpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,16 @@ class GenericTimer : public TimerBase
220220
rclcpp_timer_callback_added,
221221
static_cast<const void *>(get_timer_handle().get()),
222222
reinterpret_cast<const void *>(&callback_));
223-
TRACEPOINT(
224-
rclcpp_callback_register,
225-
reinterpret_cast<const void *>(&callback_),
226-
tracetools::get_symbol(callback_));
223+
#ifndef TRACETOOLS_DISABLED
224+
if (TRACEPOINT_ENABLED(rclcpp_callback_register)) {
225+
char * symbol = tracetools::get_symbol(callback_);
226+
DO_TRACEPOINT(
227+
rclcpp_callback_register,
228+
reinterpret_cast<const void *>(&callback_),
229+
symbol);
230+
std::free(symbol);
231+
}
232+
#endif
227233
}
228234

229235
/// Default destructor.

0 commit comments

Comments
 (0)