From 092421fabf3ae573b80370c924882cdcc6815af9 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 16 Aug 2022 19:54:29 -0300 Subject: [PATCH] lib/commit: Unref repo on success Commit 540e60c3 introduced _ostree_repo_auto_transaction_new(), a private constructor to OstreeRepoAutoTransaction, by factoring out some code from _ostree_repo_auto_transaction_start(). This factored code increased the refcount of the 'repo' variable. Subsequent commit 71304e854c made ostree_repo_prepare_transaction() use ths newly introduced constructor. However, in this function, the happy path assumed no ref was taken, and therefore did not unref it. Commit 71304e854c didn't add the corresponding unref either. This leaks a reference to OstreeRepo when calling ostree_repo_prepare_transaction(). Plug this leak by using g_clear_object() to clear the repo field of OstreeRepoAutoTransaction, instead of simply setting it to NULL. Closes https://github.com/flatpak/flatpak/issues/4928 --- src/libostree/ostree-repo-commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index 6cfdc32b..c22864cd 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -1745,7 +1745,7 @@ ostree_repo_prepare_transaction (OstreeRepo *self, return FALSE; /* Success: do not abort the transaction when returning. */ - txn->repo = NULL; (void) txn; + g_clear_object (&txn->repo); (void) txn; if (out_transaction_resume) *out_transaction_resume = ret_transaction_resume;