Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed unnecessary transfer of the ownership before release which returns the pointer itself #11726

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/track/taglib/trackmetadata_id3v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,9 @@ void writeTextIdentificationFrame(
auto pFrame =
std::make_unique<TagLib::ID3v2::TextIdentificationFrame>(id, stringType);
pFrame->setText(toTString(text));
pTag->addFrame(pFrame.get());
// Now that the plain pointer in pFrame is owned and managed by
// pTag we need to release the ownership to avoid double deletion!
pFrame.release();

// pTag takes the ownership of pFrame
pTag->addFrame(pFrame.release());
}
}

Expand Down Expand Up @@ -414,10 +413,9 @@ void writeUserTextIdentificationFrame(
std::make_unique<TagLib::ID3v2::UserTextIdentificationFrame>(stringType);
pFrame->setDescription(toTString(description));
pFrame->setText(toTString(text));
pTag->addFrame(pFrame.get());
// Now that the plain pointer in pFrame is owned and managed by
// pTag we need to release the ownership to avoid double deletion!
pFrame.release();

// pTag takes the ownership of pFrame
pTag->addFrame(pFrame.release());
}
}
}
Expand Down Expand Up @@ -488,10 +486,9 @@ void writeCommentsFrame(
std::make_unique<TagLib::ID3v2::CommentsFrame>(stringType);
pFrame->setDescription(toTString(description));
pFrame->setText(text);
pTag->addFrame(pFrame.get());
// Now that the plain pointer in pFrame is owned and managed by
// pTag we need to release the ownership to avoid double deletion!
pFrame.release();

// pTag takes the ownership of pFrame
pTag->addFrame(pFrame.release());
}
}
// Cleanup: Remove non-standard comment frames to avoid redundant and
Expand Down Expand Up @@ -576,10 +573,9 @@ void writeGeneralEncapsulatedObjectFrame(
pFrame->setDescription(toTString(description));
pFrame->setObject(toTByteVector(data));
pFrame->setMimeType(mimeType);
pTag->addFrame(pFrame.get());
// Now that the plain pointer in pFrame is owned and managed by
// pTag we need to release the ownership to avoid double deletion!
pFrame.release();

// pTag takes the ownership of pFrame
pTag->addFrame(pFrame.release());
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/util/db/dbconnectionpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ bool DbConnectionPool::createThreadLocalConnection() {
<< *pConnection;
return false; // abort
}
m_threadLocalConnections.setLocalData(pConnection.get()); // transfer ownership
pConnection.release(); // release ownership

// m_threadLocalConnections takes the ownership of pConnection
m_threadLocalConnections.setLocalData(pConnection.release());

DEBUG_ASSERT(m_threadLocalConnections.hasLocalData());
DEBUG_ASSERT(m_threadLocalConnections.localData());
kLogger.info()
Expand Down