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

rpm: Reset RPM log callback upon RpmLogGuard destruction #1870

Merged
merged 1 commit into from
Nov 18, 2024
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
10 changes: 10 additions & 0 deletions libdnf5/rpm/rpm_log_guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ static int rpmlog_callback(rpmlogRec rec, rpmlogCallbackData data) {
return 0;
}

RpmLogGuardBase::~RpmLogGuardBase() {
// Reset the RPM log callback to nullptr to prevent undefined behavior if the
// callback data retains a reference to the RpmLogGuard object after it has
// been destroyed.
// The class doesn't reset the original callback upon destruction, because
// although `rpmlogSetCallback()` returns the old callback, there's no way
// to also retrieve the `rpmlogCallbackData` associated with it, so the
// data can't be reset.
rpmlogSetCallback(nullptr, nullptr);
}

RpmLogGuard::RpmLogGuard(const BaseWeakPtr & base) : RpmLogGuardBase(), base(base) {
rpmlogSetCallback(&rpmlog_callback, this);
Expand Down
2 changes: 1 addition & 1 deletion libdnf5/rpm/rpm_log_guard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace libdnf5::rpm {
class RpmLogGuardBase {
public:
RpmLogGuardBase() : rpm_log_mutex_guard(rpm_log_mutex) {}
~RpmLogGuardBase() {}
virtual ~RpmLogGuardBase();

private:
static std::mutex rpm_log_mutex;
Expand Down
Loading