From f1dbb519ad858f90d71a74e254919dd9f29c139e Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Wed, 7 Mar 2018 13:48:40 +0100 Subject: [PATCH] fix(MainDb): avoid memory leak --- src/db/main-db.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/db/main-db.cpp b/src/db/main-db.cpp index df4a839f9..2cce4947a 100644 --- a/src/db/main-db.cpp +++ b/src/db/main-db.cpp @@ -1161,7 +1161,7 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) { const string &text = getValueFromRow(message, LegacyMessageColText, isNull); - Content *content = nullptr; + unique_ptr content; if (contentType == ContentType::FileTransfer) { const string appData = getValueFromRow(message, LegacyMessageColAppData, isNull); if (isNull) { @@ -1175,12 +1175,12 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) { continue; } ContentType fileContentType(contentTypeString); - content = new FileContent(); + content.reset(new FileContent()); content->setContentType(fileContentType); content->setAppData("legacy", appData); content->setBody(text); } else { - content = new Content(); + content.reset(new Content()); content->setContentType(contentType); if (contentType == ContentType::PlainText) { if (isNull) { @@ -1226,10 +1226,8 @@ void MainDbPrivate::importLegacyHistory (DbSession &inDbSession) { soci::use(creationTime), soci::use(state), soci::use(direction), soci::use(isSecured); - if (content) { + if (content) insertContent(eventId, *content); - delete content; - } insertChatRoomParticipant(chatRoomId, remoteSipAddressId, false); if (state != int(ChatMessage::State::Displayed))