Skip to content

Commit b9f41c5

Browse files
committed
processor_sampling: fix spans reconcile logic (fix fluent#10248)
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 538baad commit b9f41c5

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

plugins/processor_sampling/sampling_tail.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,26 @@ static struct ctrace *reconcile_and_create_ctrace(struct sampling *ctx, struct s
231231
}
232232
}
233233

234-
/* unlink active span from it original ctrace context and link it to the active scope_span list */
234+
/*
235+
* Detach the span from its previous context completely and
236+
* re-attach it to the new one. If we only move the local list
237+
* reference (span->_head) the span would still belong to the
238+
* original ctrace context which later on might lead to use after
239+
* free issues when the new context is destroyed. Make sure to
240+
* update all references.
241+
*/
242+
243+
/* detach from the original scope span and global list */
235244
cfl_list_del(&span->_head);
245+
cfl_list_del(&span->_head_global);
246+
247+
/* update parent references */
248+
span->scope_span = scope_span;
249+
span->ctx = ctr;
250+
251+
/* link to the new scope span and ctrace context */
236252
cfl_list_add(&span->_head, &scope_span->spans);
253+
cfl_list_add(&span->_head_global, &ctr->span_list);
237254

238255
/* reset all the contexts */
239256
resource_span = NULL;

0 commit comments

Comments
 (0)