From: Rusty Russell Date: Mon, 9 Jan 2023 02:23:22 +0000 (+1030) Subject: fdpass: avoid memory leak in example. X-Git-Url: http://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=3942778bb3f61cb580dd088c8449ca6dfdf6b7bc fdpass: avoid memory leak in example. Signed-off-by: Rusty Russell --- 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.