strlen(sysfs_value) return 0 do not mean sysfs_value
is NULL and this memory should be freed

Signed-off-by: Wenchao Hao <haowenc...@huawei.com>
---
 usr/sysfs.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/usr/sysfs.c b/usr/sysfs.c
index 2488160..8d37c69 100644
--- a/usr/sysfs.c
+++ b/usr/sysfs.c
@@ -574,8 +574,12 @@ int sysfs_get_str(char *id, char *subsys, char *param, 
char *value,
 
        value[0] = '\0';
        sysfs_value = sysfs_get_value(id, subsys, param);
-       if (!sysfs_value || !strlen(sysfs_value))
+       if (!sysfs_value)
+               return EIO;
+       if (!strlen(sysfs_value)) {
+               free(sysfs_value);
                return EIO;
+       }
 
        len = strlen(sysfs_value);
        if (len && (sysfs_value[len - 1] == '\n'))
-- 
2.27.0

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to open-iscsi+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/open-iscsi/20201105025925.29822-1-haowenchao%40huawei.com.

Reply via email to