Skip to content

Commit 4fb6495

Browse files
authored
Fix a couple memory leaks (#3420)
* Fix some stuff * Fix memory leak Signed-off-by: Bob Weinand <[email protected]> * Properly fix php_stream_context freeing Signed-off-by: Bob Weinand <[email protected]> --------- Signed-off-by: Bob Weinand <[email protected]>
1 parent e0956a1 commit 4fb6495

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

ext/handlers_httpstreams.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static php_stream *dd_stream_opener(
2929
php_stream_wrapper *original_wrapper,
3030
DD_STREAM_OPENER_ARGS
3131
) {
32-
if (!context) {
32+
bool temporary_context = !context;
33+
if (temporary_context) {
3334
context = php_stream_context_alloc();
3435
}
3536

@@ -98,6 +99,10 @@ static php_stream *dd_stream_opener(
9899

99100
php_stream *stream = original_wrapper->wops->stream_opener(DD_STREAM_OPENER_CALL_ARGS);
100101

102+
if (temporary_context) {
103+
zend_list_delete(context->res);
104+
}
105+
101106
if (span) {
102107
ddtrace_clear_execute_data_span((zend_ulong)-2, true);
103108
}

ext/serializer.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,8 +1357,7 @@ static void _serialize_meta(ddog_SpanBytes *rust_span, ddtrace_span_data *span,
13571357
dd_set_mapped_peer_service(rust_span, Z_STR_P(peer_service));
13581358
} else if (zend_hash_num_elements(peer_service_sources) > 0) {
13591359
zval *tag;
1360-
ZEND_HASH_FOREACH_VAL(peer_service_sources, tag)
1361-
{
1360+
ZEND_HASH_FOREACH_VAL(peer_service_sources, tag) {
13621361
if (Z_TYPE_P(tag) == IS_STRING) { // Use the first tag that is found in the span, if any
13631362
zval *peer_service = zend_hash_find(Z_ARRVAL_P(meta), Z_STR_P(tag));
13641363
if (peer_service && Z_TYPE_P(peer_service) == IS_STRING) {
@@ -1368,12 +1367,11 @@ static void _serialize_meta(ddog_SpanBytes *rust_span, ddtrace_span_data *span,
13681367
if (!dd_set_mapped_peer_service(rust_span, peer)) {
13691368
ddog_add_str_span_meta_zstr(rust_span, "peer.service", peer);
13701369
}
1371-
1370+
zend_string_release(peer);
13721371
break;
13731372
}
13741373
}
1375-
}
1376-
ZEND_HASH_FOREACH_END();
1374+
} ZEND_HASH_FOREACH_END();
13771375
}
13781376
}
13791377

src/DDTrace/Integrations/Exec/ExecIntegration.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ static function (HookData $hook) {
110110
},
111111
static function (HookData $hook) {
112112
/** @var SpanData $span */
113-
$span = $hook->data;
114-
if (!$span) {
113+
if (!$span = $hook->data ?? null) {
115114
return;
116115
}
117116

0 commit comments

Comments
 (0)