aidl/provider_info: fix possible memory leak

Bug: 305734815
Test: m com.android.btservices

Change-Id: I9f9b8bead028ccc59824428f86f0e7361d0cc9a5
diff --git a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc
index 61df226..ecb36a7 100644
--- a/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc
+++ b/system/audio_hal_interface/aidl/a2dp_encoding_aidl.cc
@@ -217,7 +217,7 @@
 // ProviderInfo for A2DP hardware offload encoding and decoding data paths,
 // if supported by the HAL and enabled. nullptr if not supported
 // or disabled.
-::bluetooth::audio::aidl::a2dp::ProviderInfo* provider_info;
+std::unique_ptr<::bluetooth::audio::aidl::a2dp::ProviderInfo> provider_info;
 
 // Save the value if the remote reports its delay before this interface is
 // initialized
diff --git a/system/audio_hal_interface/aidl/provider_info.cc b/system/audio_hal_interface/aidl/provider_info.cc
index 9d69eb3..9b86b35 100644
--- a/system/audio_hal_interface/aidl/provider_info.cc
+++ b/system/audio_hal_interface/aidl/provider_info.cc
@@ -48,7 +48,7 @@
  * getProviderInfo, or if the feature flag for codec
  * extensibility is disabled.
  ***/
-ProviderInfo* ProviderInfo::GetProviderInfo() {
+std::unique_ptr<ProviderInfo> ProviderInfo::GetProviderInfo() {
   if (!IS_FLAG_ENABLED(a2dp_offload_codec_extensibility)) {
     LOG(INFO) << "a2dp offload codec extensibility is disabled;"
               << " not going to load the ProviderInfo";
@@ -78,7 +78,8 @@
     sink_codecs = std::move(sink_provider_info->codecInfos);
   }
 
-  return new ProviderInfo(std::move(source_codecs), std::move(sink_codecs));
+  return std::make_unique<ProviderInfo>(std::move(source_codecs),
+                                        std::move(sink_codecs));
 }
 
 /***
diff --git a/system/audio_hal_interface/aidl/provider_info.h b/system/audio_hal_interface/aidl/provider_info.h
index f79dbd4..7306f25 100644
--- a/system/audio_hal_interface/aidl/provider_info.h
+++ b/system/audio_hal_interface/aidl/provider_info.h
@@ -38,7 +38,7 @@
    * getProviderInfo, or if the feature flag for codec
    * extensibility is disabled.
    ***/
-  static ProviderInfo* GetProviderInfo();
+  static std::unique_ptr<ProviderInfo> GetProviderInfo();
 
   ProviderInfo(std::vector<CodecInfo> source_codecs,
                std::vector<CodecInfo> sink_codecs);