Skip to content

Commit

Permalink
libdnf5: Load plugins with RTLD_NODELETE flag set
Browse files Browse the repository at this point in the history
Some plugins can use libraries, which have saved global data and unloading
such library can break this global data in a way which can cause a crash
of the daemon. One such library is glib, where this unload can break its
type system, with this shown on the dnf5daemon process console when it happens:

```
    (process:49835): GLib-GObject-CRITICAL **: 15:47:52.469: cannot register existing type 'AsMetadata'

    (process:49835): GLib-GObject-CRITICAL **: 15:47:52.469: cannot add private field to invalid (non-instantiatable) type '<invalid>'

    (process:49835): GLib-CRITICAL **: 15:47:52.469: g_once_init_leave_pointer: assertion 'result != 0' failed

    (process:49835): GLib-GObject-CRITICAL **: 15:47:52.469: g_object_new_with_properties: assertion 'G_TYPE_IS_OBJECT (object_type)' failed
    Segmentation fault (core dumped)
```
  • Loading branch information
mcrha committed Jan 7, 2025
1 parent 68ed27b commit cde45bc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion libdnf5/utils/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
namespace libdnf5::utils {

Library::Library(const std::string & path) : path(path) {
handle = dlopen(path.c_str(), RTLD_LAZY);
// the NODELETE is needed to not garbage plugin's libraries global data,
// like when the plugin uses glib, then it could break its type system
handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_NODELETE);
if (!handle) {
const char * err_msg = dlerror(); // returns localized message, problem with later translation
throw LibraryLoadingError(M_("Cannot load shared library \"{}\": {}"), path, std::string(err_msg));
Expand Down

0 comments on commit cde45bc

Please sign in to comment.