There is a potential use-after-free bug in the OpenTelemetry C++ SDK metrics implementation.
Problem:
-
Metric storage class(SyncMetricStorage) store a raw pointer to the AttributesProcessor instance, which is owned by the associated View.
-
The View (and its AttributesProcessor) is owned by the ViewRegistry, which is managed by the MeterContext and ultimately the MeterProvider.
-
When the MeterProvider is shut down or destroyed, the ViewRegistry and its Views are deleted, invalidating the AttributesProcessor pointer inside any metric storage objects.
-
If metric instruments are recorded after shutdown (especially from other threads, background tasks, or due to application logic errors), this leads to use-after-free, undefined behavior, and possible segmentation faults.