[PATCH] gpioset: fix memory leak in interactive mode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Even when readline() returns an empty buffer, we still need to free() it to
avoid leaking memory.

Signed-off-by: Esben Haabendal <esben@xxxxxxxxxx>
---
 tools/gpioset.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/gpioset.c b/tools/gpioset.c
index c49d229870d2..f087003af1c9 100644
--- a/tools/gpioset.c
+++ b/tools/gpioset.c
@@ -768,8 +768,12 @@ static void interact(struct gpiod_line_request **requests,
 		fflush(stdout);
 
 		line = readline(PROMPT);
-		if (!line || line[0] == '\0')
+		if (!line)
 			continue;
+		if (line[0] == '\0') {
+			free(line);
+			continue;
+		}
 
 		for (i = strlen(line) - 1; (i > 0) && isspace(line[i]); i--)
 			line[i] = '\0';
-- 
2.38.1




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux