Thread (134 messages) flat view 134 messages, 4 authors, 2016-06-15
STALE3743d

Revision v8 of 7 in this series.

Revisions (7)
  1. v4 [diff vs current]
  2. v5 [diff vs current]
  3. v6 [diff vs current]
  4. v7 [diff vs current]
  5. v8 current
  6. v9 [diff vs current]
  7. v10 [diff vs current]

[PATCH v8 20/44] refs.c: free the transaction before returning when number of updates is 0

From: Ronnie Sahlberg <hidden>
Date: 2016-06-15 23:01:10
Subsystem: the rest · Maintainer: Linus Torvalds

We have to free the transaction before returning in the early check for
'return early if number of updates == 0' or else the following code would
create a memory leak with the transaction never being freed :
   t = ref_transaction_begin()
   ref_transaction_commit(t)

Signed-off-by: Ronnie Sahlberg <redacted>
---
 refs.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/refs.c b/refs.c
index 0476892..4a37f87 100644
--- a/refs.c
+++ b/refs.c
@@ -3471,8 +3471,10 @@ int ref_transaction_commit(struct ref_transaction *transaction,
 	int n = transaction->nr;
 	struct ref_update **updates = transaction->updates;
 
-	if (!n)
+	if (!n) {
+		ref_transaction_free(transaction);
 		return 0;
+	}
 
 	/* Allocate work space */
 	delnames = xmalloc(sizeof(*delnames) * n);
-- 
2.0.0.rc3.477.g0f8edf7
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help