Commit 57ebf19f2d3fab10b9053e7c865cbd251e1ded0d

Hiltjo Posthuma 2019-08-27T19:00:15

buf_alloc: free whole BUF* in allocation failure path

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/lib/buf.c b/lib/buf.c
index eb235b0..b744f0f 100644
--- a/lib/buf.c
+++ b/lib/buf.c
@@ -69,8 +69,10 @@ buf_alloc(size_t len)
 	/* Postpone creation of zero-sized buffers */
 	if (len > 0) {
 		b->cb_buf = calloc(1, len);
-		if (b->cb_buf == NULL)
+		if (b->cb_buf == NULL) {
+			free(b);
 			return NULL;
+		}
 	} else
 		b->cb_buf = NULL;