From 4e1fe736af1b88485bba762b11bc0c11a447819c Mon Sep 17 00:00:00 2001 From: Jeff Tinker Date: Mon, 8 May 2017 19:27:10 -0700 Subject: [PATCH] Fix resource leaks in drm hal bug:36408047 test: manual tests to verify leaks are fixed Change-Id: Idd79e99e211d81f8b3e58cf52c9b01ce9d370dc4 --- drm/1.0/default/CryptoPlugin.h | 2 +- drm/1.0/default/DrmFactory.cpp | 2 +- drm/1.0/default/DrmPlugin.cpp | 36 ++++++++++++++++++++++++------------ drm/1.0/default/DrmPlugin.h | 4 ++-- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/drm/1.0/default/CryptoPlugin.h b/drm/1.0/default/CryptoPlugin.h index 11cc2aae..5da469ce 100644 --- a/drm/1.0/default/CryptoPlugin.h +++ b/drm/1.0/default/CryptoPlugin.h @@ -44,7 +44,7 @@ using ::android::sp; struct CryptoPlugin : public ICryptoPlugin { CryptoPlugin(android::CryptoPlugin *plugin) : mLegacyPlugin(plugin) {} - ~CryptoPlugin() {delete mLegacyPlugin;} + virtual ~CryptoPlugin() {delete mLegacyPlugin;} // Methods from ::android::hardware::drm::V1_0::ICryptoPlugin // follow. diff --git a/drm/1.0/default/DrmFactory.cpp b/drm/1.0/default/DrmFactory.cpp index 7e5d998e..05951d7c 100644 --- a/drm/1.0/default/DrmFactory.cpp +++ b/drm/1.0/default/DrmFactory.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2016 The Android Open Source Project -` * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/drm/1.0/default/DrmPlugin.cpp b/drm/1.0/default/DrmPlugin.cpp index 1695ef77..1feec0a3 100644 --- a/drm/1.0/default/DrmPlugin.cpp +++ b/drm/1.0/default/DrmPlugin.cpp @@ -327,24 +327,27 @@ namespace implementation { Return DrmPlugin::sendEvent(EventType eventType, const hidl_vec& sessionId, const hidl_vec& data) { - if (mListener != nullptr) { - mListener->sendEvent(eventType, sessionId, data); + auto listener = mListener.promote(); + if (listener != nullptr) { + listener->sendEvent(eventType, sessionId, data); } return Void(); } Return DrmPlugin::sendExpirationUpdate( const hidl_vec& sessionId, int64_t expiryTimeInMS) { - if (mListener != nullptr) { - mListener->sendExpirationUpdate(sessionId, expiryTimeInMS); + auto listener = mListener.promote(); + if (listener != nullptr) { + listener->sendExpirationUpdate(sessionId, expiryTimeInMS); } return Void(); } Return DrmPlugin::sendKeysChange(const hidl_vec& sessionId, const hidl_vec& keyStatusList, bool hasNewUsableKey) { - if (mListener != nullptr) { - mListener->sendKeysChange(sessionId, keyStatusList, hasNewUsableKey); + auto listener = mListener.promote(); + if (listener != nullptr) { + listener->sendKeysChange(sessionId, keyStatusList, hasNewUsableKey); } return Void(); } @@ -380,15 +383,21 @@ namespace implementation { } if (sendEvent) { Vector emptyVector; - mListener->sendEvent(eventType, - toHidlVec(sessionId == NULL ? emptyVector: *sessionId), - toHidlVec(data == NULL ? emptyVector: *data)); + auto listener = mListener.promote(); + if (listener != nullptr) { + listener->sendEvent(eventType, + toHidlVec(sessionId == NULL ? emptyVector: *sessionId), + toHidlVec(data == NULL ? emptyVector: *data)); + } } } void DrmPlugin::sendExpirationUpdate(Vector const *sessionId, int64_t expiryTimeInMS) { - mListener->sendExpirationUpdate(toHidlVec(*sessionId), expiryTimeInMS); + auto listener = mListener.promote(); + if (listener != nullptr) { + listener->sendExpirationUpdate(toHidlVec(*sessionId), expiryTimeInMS); + } } void DrmPlugin::sendKeysChange(Vector const *sessionId, @@ -424,8 +433,11 @@ namespace implementation { keyStatus.keyId = toHidlVec(legacyKeyStatus.mKeyId); keyStatusVec.push_back(keyStatus); } - mListener->sendKeysChange(toHidlVec(*sessionId), - toHidlVec(keyStatusVec), hasNewUsableKey); + auto listener = mListener.promote(); + if (listener != nullptr) { + listener->sendKeysChange(toHidlVec(*sessionId), + toHidlVec(keyStatusVec), hasNewUsableKey); + } } } // namespace implementation diff --git a/drm/1.0/default/DrmPlugin.h b/drm/1.0/default/DrmPlugin.h index dce6c0c6..d951c926 100644 --- a/drm/1.0/default/DrmPlugin.h +++ b/drm/1.0/default/DrmPlugin.h @@ -46,7 +46,7 @@ using ::android::sp; struct DrmPlugin : public IDrmPlugin, android::DrmPluginListener { DrmPlugin(android::DrmPlugin *plugin) : mLegacyPlugin(plugin) {} - ~DrmPlugin() {delete mLegacyPlugin;} + virtual ~DrmPlugin() {delete mLegacyPlugin;} // Methods from ::android::hardware::drm::V1_0::IDrmPlugin follow. @@ -153,7 +153,7 @@ struct DrmPlugin : public IDrmPlugin, android::DrmPluginListener { private: android::DrmPlugin *mLegacyPlugin; - sp mListener; + wp mListener; DrmPlugin() = delete; DrmPlugin(const DrmPlugin &) = delete; -- 2.11.0