[mmc-utils,2/5] Cleanup memory in error case
diff mbox series

Message ID 20181218143601.24413-3-michael.heimpold@i2se.com
State New
Headers show
Series
  • Various fixes for mmc-utils
Related show

Commit Message

Michael Heimpold Dec. 18, 2018, 2:35 p.m. UTC
In case that we leave due to malformed string,
free the allocated memory before returning.

Signed-off-by: Michael Heimpold <michael.heimpold@i2se.com>
Cc: Michael Heimpold <mhei@heimpold.de>
---
 lsmmc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch
diff mbox series

diff --git a/lsmmc.c b/lsmmc.c
index e514c83..a53bc57 100644
--- a/lsmmc.c
+++ b/lsmmc.c
@@ -378,8 +378,10 @@  char *to_binstr(char *hexstr)
 		return NULL;
 
 	while (hexstr && *hexstr != '\0') {
-		if (!isxdigit(*hexstr))
+		if (!isxdigit(*hexstr)) {
+			free(binstr);
 			return NULL;
+		}
 
 		if (isdigit(*hexstr))
 			strcat(binstr, bindigits[*hexstr - '0']);