qemu-io: Fix memory leak
PATCH 1/1 qemu-io: Fix memory leak
--- qemu-io.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
qemu-io.c +6 -4
@@ -129,7 +129,8 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) {size_t *sizes =calloc (nr_iov,sizeof (size_t ));size_t count =0 ; -void *buf, *p; +void *buf =NULL ; +void *p;int i;for (i =0 ; i < nr_iov; i++) {
@@ -139,19 +140,19 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) len =cvtnum (arg);if (len <0 ) {printf ("non-numeric length argument -- %s\n" , arg); -return NULL ; + goto fail; }/* should be SIZE_T_MAX, but that doesn't exist */ if (len >UINT_MAX ) {printf ("too large length argument -- %s\n" , arg); -return NULL ; + goto fail; }if (len &0x1ff ) {printf ("length argument %lld is not sector aligned\n" , len); -return NULL ; + goto fail; } sizes[i] = len;
@@ -167,6 +168,7 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) p += sizes[i]; } +fail:free (sizes);return buf; }
Signature · 1 line
1.6.2.5
Looks good,
Quoted 10 lines · Kevin Wolf
Signed-off-by Kevin Wolf <[email protected]>--- qemu-io.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)qemu-io.c +0
-0
qemu-io.c create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) · line 134
Quoted 7 lines
qemu-io.c +2
-1@@ -129,7 +129,8 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) {size_t *sizes =calloc (nr_iov,sizeof (size_t ));size_t count =0 ; -void *buf, *p; +void *buf =NULL ; +void *p;int i;
I'd prefer the init to happen after the declarations -- brings in consistent style, puts declarations in one blob and makes initialisations explicit.
Amit
Am 20.11.2009 09:05, schrieb Amit Shah:
Quoted 6 lines · Kevin Wolf
Quoted 5 lines
Signed-off-by Kevin Wolf <[email protected]>--- qemu-io.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
Quoted 16 lines
qemu-io.c create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) · line 134
Quoted 12 lines
qemu-io.c +2
-1@@ -129,7 +129,8 @@ create_iovec(QEMUIOVector *qiov, char **argv, int nr_iov, int pattern) {size_t *sizes =calloc (nr_iov,sizeof (size_t ));size_t count =0 ; -void *buf, *p; +void *buf =NULL ; +void *p;int i;I'd prefer the init to happen after the declarations -- brings in consistent style, puts declarations in one blob and makes initialisations explicit.
In the context of this function it would be inconsistent, and I'd be surprised if the rest of the qemu code was consistent with your expectations. After all, it's a matter of taste, and in such questions I tend to stick with the style of the surrounding code.
Kevin