
If malloc() fails inside jtrans_add(), we leave ts->lock locked, which will
cause a deadlock if we try to do almost any other operation with the
transaction (in fact, freeing it will also make pthread_mutex_destroy() fail).

This patch fixes it by unlocking before returning in those cases.

Thanks to Shehjar Tikoo for the report.

---

 cur-root/trans.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff -puN trans.c~unlock_in_jtrans_add trans.c
--- cur/trans.c~unlock_in_jtrans_add	2004-08-28 21:22:53.992139592 -0300
+++ cur-root/trans.c	2004-08-28 21:22:53.996138984 -0300
@@ -140,16 +140,20 @@ int jtrans_add(struct jtrans *ts, const 
 	pthread_mutex_lock(&(ts->lock));
 	if (ts->op == NULL) {
 		ts->op = malloc(sizeof(struct joper));
-		if (ts->op == NULL)
+		if (ts->op == NULL) {
+			pthread_mutex_unlock(&(ts->lock));
 			return 0;
+		}
 		jop = ts->op;
 		jop->prev = NULL;
 	} else {
 		for (tmpop = ts->op; tmpop->next != NULL; tmpop = tmpop->next)
 			;
 		tmpop->next = malloc(sizeof(struct joper));
-		if (tmpop->next == NULL)
+		if (tmpop->next == NULL) {
+			pthread_mutex_unlock(&(ts->lock));
 			return 0;
+		}
 		tmpop->next->prev = tmpop;
 		jop = tmpop->next;
 	}
_
