git » libjio » commit 609bd0b

Check malloc() return value properly in jtrans_add().

author Alberto Bertogli
2004-07-22 14:08:38 UTC
committer Alberto Bertogli
2007-07-15 13:16:57 UTC
parent 7f3bdae0c32a8958b44519107968cc41b67c1e2b

Check malloc() return value properly in jtrans_add().

Check malloc() return value properly in jtrans_add().

trans.c +4 -5

diff --git a/trans.c b/trans.c
index eec5aef..5425553 100644
--- a/trans.c
+++ b/trans.c
@@ -139,22 +139,21 @@ int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offset)
 	pthread_mutex_lock(&(ts->lock));
 	if (ts->op == NULL) {
 		ts->op = malloc(sizeof(struct joper));
+		if (ts->op == NULL)
+			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)
+			return 0;
 		tmpop->next->prev = tmpop;
 		jop = tmpop->next;
 	}
 	pthread_mutex_unlock(&(ts->lock));
 
-	if (jop == NULL) {
-		/* malloc() failed */
-		return 0;
-	}
-
 	jop->buf = malloc(count);
 	if (jop->buf == NULL) {
 		free(jop);