mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zdev: fix memory leak in misc_readlink()
When realloc() fails to allocate memory it returns NULL and the original block is left untouched. In that case return the potentially larger original block. Found using Cppcheck: [zdev/src/misc.c:1106]: (error) Memory leak: name Cc: Peter Oberparleiter <peter.oberparleiter@de.ibm.com> Signed-off-by: Jens Remus <jremus@linux.ibm.com> Reviewed-by: Peter Oberparleiter <oberpar@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* zdev - Modify and display the persistent configuration of devices
|
||||
*
|
||||
* Copyright IBM Corp. 2016, 2017
|
||||
* Copyright IBM Corp. 2016, 2018
|
||||
*
|
||||
* s390-tools is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the MIT license. See LICENSE for details.
|
||||
@@ -1091,7 +1091,7 @@ exit_code_t misc_write_text_file_retry(const char *path, const char *text,
|
||||
* at the specified path or NULL on error. */
|
||||
char *misc_readlink(const char *path)
|
||||
{
|
||||
char *name;
|
||||
char *name, *name2;
|
||||
ssize_t len;
|
||||
|
||||
debug("Reading link %s\n", path);
|
||||
@@ -1103,7 +1103,8 @@ char *misc_readlink(const char *path)
|
||||
}
|
||||
name[len++] = 0;
|
||||
|
||||
return realloc(name, len);
|
||||
name2 = realloc(name, len);
|
||||
return (name2) ? name2 : name;
|
||||
}
|
||||
|
||||
/* Determine configuration set. */
|
||||
|
||||
Reference in New Issue
Block a user