diff options
author | Wenchao Hao <haowenchao@huawei.com> | 2020-11-04 16:19:14 +0800 |
---|---|---|
committer | Wenchao Hao <haowenchao@huawei.com> | 2020-11-04 16:25:32 +0800 |
commit | 84843e5ffe2c70e0bef58ffc444562e59fc7d2f0 (patch) | |
tree | 4543bd996aa16aed8f1afb2b37957aa03d7b8429 | |
parent | 348f093311f289635f9e85129aad944ffe1eda91 (diff) | |
download | open-iscsi-84843e5ffe2c70e0bef58ffc444562e59fc7d2f0.tar.gz |
Fix memory leak in sysfs_get_str
strlen(sysfs_value) return 0 do not mean sysfs_value
is NULL and this memory should be freed
Signed-off-by: Wenchao Hao <haowenchao@huawei.com>
-rw-r--r-- | usr/sysfs.c | 6 |
1 files changed, 5 insertions, 1 deletions
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')) |