Skip to content

Commit

Permalink
Base: Impl has to be the second data member after base_guard to be de…
Browse files Browse the repository at this point in the history
…stroyed last

SolvRepo relies on the fact that pointers in libsolv repos are always
valid.
c8e26cb
  • Loading branch information
kontura authored and jrohel committed Nov 2, 2022
1 parent 7dbcb61 commit 66e0a75
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
10 changes: 6 additions & 4 deletions include/libdnf/base/base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ class Base {
friend class libdnf::advisory::AdvisoryQuery;
friend class libdnf::repo::SolvRepo;

WeakPtrGuard<Base, false> base_guard;

/// Loads the default configuration. To load distribution-specific configuration.
void load_defaults();

Expand All @@ -123,6 +121,12 @@ class Base {
/// The files in the directory are read in alphabetical order.
void load_config_from_dir();

WeakPtrGuard<Base, false> base_guard;
// Impl has to be the second data member (right after base_guard which is needed for its construction) because it
// contains Pool and that has be destructed last.
// See commit: https://github.com/rpm-software-management/dnf5/commit/c8e26cb545aed0d6ca66545d51eda7568efdf232
ImplPtr<Impl> p_impl;

LogRouter log_router;
ConfigMain config;
repo::RepoSack repo_sack;
Expand All @@ -136,8 +140,6 @@ class Base {

WeakPtrGuard<LogRouter, false> log_router_gurad;
WeakPtrGuard<Vars, false> vars_gurad;

ImplPtr<Impl> p_impl;
};

} // namespace libdnf
Expand Down
6 changes: 3 additions & 3 deletions libdnf/base/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ static std::atomic<Base *> locked_base{nullptr};
static std::mutex locked_base_mutex;

Base::Base(std::vector<std::unique_ptr<Logger>> && loggers)
: log_router(std::move(loggers)),
: p_impl(new Impl(get_weak_ptr())),
log_router(std::move(loggers)),
repo_sack(get_weak_ptr()),
rpm_package_sack(get_weak_ptr()),
transaction_history(get_weak_ptr()),
vars(get_weak_ptr()),
p_impl(new Impl(get_weak_ptr())) {
vars(get_weak_ptr()) {
load_defaults();
}

Expand Down
1 change: 1 addition & 0 deletions libdnf/base/base_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Base::Impl {
friend class Base;
Impl(const libdnf::BaseWeakPtr & base);

// Pool as the owner of underlying libsolv data, has to be the first member so that it is destroyed last.
std::unique_ptr<solv::Pool> pool;

std::optional<libdnf::system::State> system_state;
Expand Down

0 comments on commit 66e0a75

Please sign in to comment.