From 718596eacef6f1c7fe58f861b6b344e063f5370a Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Tue, 5 Dec 2017 19:01:43 +0000 Subject: [PATCH] libpriv/util: add precondition to catch potential trap Basically, it doesn't make sense for the caller to only want the pkglist, but not the refsack because the former has a more limited lifetime than the latter. Check for that to make sure nobody falls in this trap like I did. Closes: #1134 Approved by: cgwalters --- src/libpriv/rpmostree-rpm-util.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libpriv/rpmostree-rpm-util.c b/src/libpriv/rpmostree-rpm-util.c index a82b1eae..871bab5e 100644 --- a/src/libpriv/rpmostree-rpm-util.c +++ b/src/libpriv/rpmostree-rpm-util.c @@ -890,6 +890,10 @@ rpmostree_get_pkglist_for_root (int dfd, GCancellable *cancellable, GError **error) { + /* the DnfPackage objects don't have a ref on their DnfSack; make sure callers don't fall + * in that trap */ + g_return_val_if_fail (out_pkglist == NULL || out_refsack != NULL, FALSE); + g_autoptr(RpmOstreeRefSack) refsack = rpmostree_get_refsack_for_root (dfd, path, cancellable, error); if (!refsack)