refs.c: allow passing NULL to ref_transaction_free
authorRonnie Sahlberg <sahlberg@google.com>
Fri, 20 Jun 2014 14:42:45 +0000 (07:42 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Jul 2014 18:54:40 +0000 (11:54 -0700)
Allow ref_transaction_free(NULL) as a no-op. This makes ref_transaction_free
easier to use and more similar to plain 'free'.

In particular, it lets us rollback unconditionally as part of cleanup code
after setting 'transaction = NULL' if a transaction has been committed or
rolled back already.

Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Ronnie Sahlberg <sahlberg@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Michael Haggerty <mhagger@alum.mit.edu>
refs.c
diff --git a/refs.c b/refs.c
index 21ed46534ab81aa966860a8eaad6e499d9e2b2c3..1d6dece4266226b3a3b6f44a0afc006ac39151c4 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -3338,6 +3338,9 @@ void ref_transaction_free(struct ref_transaction *transaction)
 {
        int i;
 
+       if (!transaction)
+               return;
+
        for (i = 0; i < transaction->nr; i++)
                free(transaction->updates[i]);