Pino Toscano
2018-Apr-30 11:07 UTC
[Libguestfs] [PATCH 3/4] common/qemuopts: use the old pointer as realloc pointer
Call realloc() directly with the pointer to the old data, instead of assigning it to the destination variable, and using that one. The rest of the code is the same, already properly checking for the results of realloc(), so this mostly help static code analyzers. --- common/qemuopts/qemuopts.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/qemuopts/qemuopts.c b/common/qemuopts/qemuopts.c index c40d44783..b3e69e306 100644 --- a/common/qemuopts/qemuopts.c +++ b/common/qemuopts/qemuopts.c @@ -168,8 +168,7 @@ extend_options (struct qemuopts *qopts) qopts->nr_alloc = 1; else qopts->nr_alloc *= 2; - new_options = qopts->options; - new_options = realloc (new_options, + new_options = realloc (qopts->options, qopts->nr_alloc * sizeof (struct qopt)); if (new_options == NULL) return NULL; @@ -421,8 +420,7 @@ qemuopts_append_arg_list (struct qemuopts *qopts, const char *value) if (value_copy == NULL) return -1; - new_values = qopt->values; - new_values = realloc (new_values, (len+2) * sizeof (char *)); + new_values = realloc (qopt->values, (len+2) * sizeof (char *)); if (new_values == NULL) { free (value_copy); return -1; -- 2.14.3
Maybe Matching Threads
- [PATCH] common/qemuopts: ensure arg lists are never empty
- [PATCH 0/4] common: Add a simple mini-library for handling qemu command and config files.
- [PATCH] (4/4) add loss option to network delay scheduler
- [PATCH] Replace -nodefconfig with -no-user-config.
- [PATCH 2.6] update to network emulation QOS scheduler