From 3942778bb3f61cb580dd088c8449ca6dfdf6b7bc Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 9 Jan 2023 12:53:22 +1030 Subject: [PATCH] fdpass: avoid memory leak in example. Signed-off-by: Rusty Russell --- ccan/io/fdpass/_info | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ccan/io/fdpass/_info b/ccan/io/fdpass/_info index ba09025a..0b10e8a8 100644 --- a/ccan/io/fdpass/_info +++ b/ccan/io/fdpass/_info @@ -32,12 +32,20 @@ * read_more, buf); * } * + * // Clean up allocation so -fsanitize=address doesn't see leak! + * static void free_buf(struct io_conn *c, struct buf *buf) + * { + * free(buf); + * } + * * // Child has received fd, start reading loop. * static struct io_plan *got_infd(struct io_conn *conn, int *infd) * { * struct buf *buf = calloc(1, sizeof(*buf)); + * struct io_conn *new_conn; * - * io_new_conn(NULL, *infd, read_more, buf); + * new_conn = io_new_conn(NULL, *infd, read_more, buf); + * io_set_finish(new_conn, free_buf, buf); * return io_close(conn); * } * // Child is receiving the fd to read into. -- 2.39.2