From 1aaa23808b012ea8173df79bcdf4d26428767745 Mon Sep 17 00:00:00 2001 From: Magnus Melin Date: Mon, 12 Apr 2021 11:48:22 +0300 Subject: [PATCH] Bug 1668926 - fix resource leakage in MsgGetFileStream. r=benc Found by coverity. leaked_storage: Variable newFileStream going out of scope leaks the storage it points to. CID 1137477 Differential Revision: https://phabricator.services.mozilla.com/D111547 --HG-- extra : rebase_source : 87f6ef054782ca9c3f4db289fbd342cc5c6def2e extra : amend_source : 99e89ab70cd7ba571dfbfbc3097cff99eb7c248e --- mailnews/base/src/nsMsgUtils.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mailnews/base/src/nsMsgUtils.cpp b/mailnews/base/src/nsMsgUtils.cpp index 45f6af55ab..294b35e2a8 100644 --- a/mailnews/base/src/nsMsgUtils.cpp +++ b/mailnews/base/src/nsMsgUtils.cpp @@ -1273,8 +1273,7 @@ nsresult MsgCleanupTempFiles(const char* fileName, const char* extension) { } nsresult MsgGetFileStream(nsIFile* file, nsIOutputStream** fileStream) { - nsMsgFileStream* newFileStream = new nsMsgFileStream; - NS_ENSURE_TRUE(newFileStream, NS_ERROR_OUT_OF_MEMORY); + RefPtr newFileStream = new nsMsgFileStream; nsresult rv = newFileStream->InitWithFile(file); if (NS_SUCCEEDED(rv)) rv = newFileStream->QueryInterface(NS_GET_IID(nsIOutputStream), @@ -1284,10 +1283,10 @@ nsresult MsgGetFileStream(nsIFile* file, nsIOutputStream** fileStream) { nsresult MsgReopenFileStream(nsIFile* file, nsIInputStream* fileStream) { nsMsgFileStream* msgFileStream = static_cast(fileStream); - if (msgFileStream) + if (msgFileStream) { return msgFileStream->InitWithFile(file); - else - return NS_ERROR_FAILURE; + } + return NS_ERROR_FAILURE; } nsresult MsgNewBufferedFileOutputStream(nsIOutputStream** aResult,