[PATCH mmc-utils 2/5] Cleanup memory in error case

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

 



In case that we leave due to malformed string,
free the allocated memory before returning.

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

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']);
-- 
2.17.1




[Index of Archives]     [Linux Memonry Technology]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux