Closed sjinks closed 1 week ago
Looks the same issue as https://github.com/open-telemetry/opentelemetry-cpp/issues/2651.
The ostream exporter is for testing purpose and is not meant to be used with BatchLogExporter. It uses ReadWriteRecordable
which doesn't make a copy the parameter in type char *
.
Confirmed, it works fine with OtlpHttpLogRecordExporter
.
Thanks for the confirmation.
I forgot to say, impressive steps to reproduce, with a dedicated git repository and all.
Feel free to close this report, we will keep #2651 opened to fix the ostream exporter.
Describe your environment OpenTelemetry v1.17.0
Steps to reproduce Sample code: https://github.com/sjinks/otel-heap-use-after-free Sample run: https://github.com/sjinks/otel-heap-use-after-free/actions/runs/11758831588/job/32757617053
What is the expected behavior? There should be no errors.
What is the actual behavior? The application crashed because of the heap-use-after-free-error
Additional context
The bug happens when the
catch
block is left before theBatchLogRecordProcessor
processes the data.My understanding is that the log message is stored
ReadWriteLogRecord::body_
which isopentelemetry::common::AttributeValue
, anostd::variant
holding aconst char*
value. Whene
goes out of the scope and gets destructed, the memory pointed to bye.what()
is also freed. However, becauseAttributeValue
does not own the data, it is left with a dangling pointer.The fix will probably be to replace
AttributeValue
withOwnedAttributeValue
(this will affectbody_
andattributes_map_
).Refs: