From ecf30a1ccf756776dfea440e4cf9b0b54581075f Mon Sep 17 00:00:00 2001 From: Guozhonghua Date: Mar 19 2024 16:19:24 +0000 Subject: sanlock: fix memory leaks on io timeout error paths Signed-off-by: Guozhonghua --- diff --git a/src/paxos_lease.c b/src/paxos_lease.c index 2ad960d..756469e 100644 --- a/src/paxos_lease.c +++ b/src/paxos_lease.c @@ -2565,8 +2565,13 @@ int paxos_lease_init(struct task *task, if (rv == SANLK_AIO_TIMEOUT) aio_timeout = 1; - if (rv < 0) + if (rv < 0) { + if (!aio_timeout) { + free(iobuf); + iobuf = NULL; + } return rv; + } } if (!aio_timeout) diff --git a/src/rindex.c b/src/rindex.c index 0ac503e..a4196d2 100644 --- a/src/rindex.c +++ b/src/rindex.c @@ -268,7 +268,10 @@ static int read_rindex(struct task *task, rv = read_iobuf(rx->disk->fd, rx->disk->offset, iobuf, iobuf_len, task, spi->io_timeout, NULL); if (rv < 0) { - free(iobuf); + if (rv != SANLK_AIO_TIMEOUT) { + free(iobuf); + iobuf = NULL; + } return rv; }