From 67810646ca83b77940eb9b54c507d2940eabf7c6 Mon Sep 17 00:00:00 2001 From: Zhizhou Yang Date: Tue, 15 Aug 2017 16:43:12 -0700 Subject: [PATCH] Fix memory leak warning in FwdLockEngine.cpp If addValue does not succeed, there will be memory leak on decodeSession. Fixed it by checking if addValue returns true first. Plus fixed a small indentation error. Test: mmm with static analyzer and warning disappears. Change-Id: Ibf9b85e4c416e8fea8b80a3ba47f87f88573c54c --- .../forward-lock/FwdLockEngine/src/FwdLockEngine.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp index 830def931c..73eea89249 100644 --- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp +++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp @@ -502,8 +502,8 @@ status_t FwdLockEngine::onOpenDecryptSession(int /* uniqueId */, int retVal = FwdLockFile_CheckHeaderIntegrity(fileDesc); DecodeSession* decodeSession = new DecodeSession(fileDesc); - if (retVal && NULL != decodeSession) { - decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession); + if (retVal && NULL != decodeSession && + decodeSessionMap.addValue(decryptHandle->decryptId, decodeSession)) { const char *pmime= FwdLockFile_GetContentType(fileDesc); String8 contentType = String8(pmime == NULL ? "" : pmime); contentType.toLower(); @@ -513,7 +513,11 @@ status_t FwdLockEngine::onOpenDecryptSession(int /* uniqueId */, decryptHandle->decryptInfo = NULL; result = DRM_NO_ERROR; } else { - LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); + if (retVal && NULL != decodeSession) { + LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession Integrity Check failed for the fd"); + } else { + LOG_VERBOSE("FwdLockEngine::onOpenDecryptSession DecodeSesssion insertion failed"); + } FwdLockFile_detach(fileDesc); delete decodeSession; } @@ -631,7 +635,7 @@ ssize_t FwdLockEngine::onRead(int /* uniqueId */, ssize_t size = -1; if (NULL != decryptHandle && - decodeSessionMap.isCreated(decryptHandle->decryptId) && + decodeSessionMap.isCreated(decryptHandle->decryptId) && NULL != buffer && numBytes > -1) { DecodeSession* session = decodeSessionMap.getValue(decryptHandle->decryptId);