buf_alloc: free whole BUF* in allocation failure path
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;