All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Denis Plotnikov <dplotnikov@virtuozzo.com>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Qemu-block <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] [PULL v2 01/16] qemu-io: add pattern file for write command
Date: Tue, 10 Sep 2019 09:19:57 +0200	[thread overview]
Message-ID: <3311e590-d2c1-2388-27cf-981c917881ab@redhat.com> (raw)
In-Reply-To: <CAFEAcA_Gpw14Hjr7rW0Z-9Ngj5Udbxv0ZEMZAo0W0PT0nCwe2g@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2949 bytes --]

On 09.09.19 19:26, Peter Maydell wrote:
> On Tue, 3 Sep 2019 at 14:35, Max Reitz <mreitz@redhat.com> wrote:
>>
>> From: Denis Plotnikov <dplotnikov@virtuozzo.com>
>>
>> The patch allows to provide a pattern file for write
>> command. There was no similar ability before.
>>
>> Signed-off-by: Denis Plotnikov <dplotnikov@virtuozzo.com>
>> Message-id: 20190820164616.4072-1-dplotnikov@virtuozzo.com
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> [mreitz: Keep optstring in alphabetical order]
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
> 
> Hi; Coverity finds a FILE* leak in this code (CID 1405303):

Thanks for the heads-up.  Denis, do you want to write a patch?

Max

>> +/*
>> + * qemu_io_alloc_from_file()
>> + *
>> + * Allocates the buffer and populates it with the content of the given file
>> + * up to @len bytes. If the file length is less than @len, then the buffer
>> + * is populated with the file content cyclically.
>> + *
>> + * @blk - the block backend where the buffer content is going to be written to
>> + * @len - the buffer length
>> + * @file_name - the file to read the content from
>> + *
>> + * Returns: the buffer pointer on success
>> + *          NULL on error
>> + */
>> +static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
>> +                                     const char *file_name)
>> +{
>> +    char *buf, *buf_origin;
>> +    FILE *f = fopen(file_name, "r");
> 
> Here we allocate the FILE*...
> 
>> +    int pattern_len;
>> +
>> +    if (!f) {
>> +        perror(file_name);
>> +        return NULL;
>> +    }
>> +
>> +    if (qemuio_misalign) {
>> +        len += MISALIGN_OFFSET;
>> +    }
>> +
>> +    buf_origin = buf = blk_blockalign(blk, len);
>> +
>> +    if (qemuio_misalign) {
>> +        buf_origin += MISALIGN_OFFSET;
>> +        buf += MISALIGN_OFFSET;
>> +        len -= MISALIGN_OFFSET;
>> +    }
>> +
>> +    pattern_len = fread(buf_origin, 1, len, f);
>> +
>> +    if (ferror(f)) {
>> +        perror(file_name);
>> +        goto error;
> 
> ...but in this error-exit path...
> 
>> +    }
>> +
>> +    if (pattern_len == 0) {
>> +        fprintf(stderr, "%s: file is empty\n", file_name);
>> +        goto error;
> 
> ...and this one...
> 
>> +    }
>> +
>> +    fclose(f);
>> +
>> +    if (len > pattern_len) {
>> +        len -= pattern_len;
>> +        buf += pattern_len;
>> +
>> +        while (len > 0) {
>> +            size_t len_to_copy = MIN(pattern_len, len);
>> +
>> +            memcpy(buf, buf_origin, len_to_copy);
>> +
>> +            len -= len_to_copy;
>> +            buf += len_to_copy;
>> +        }
>> +    }
>> +
>> +    return buf_origin;
>> +
>> +error:
>> +    qemu_io_free(buf_origin);
>> +    return NULL;
> 
> ...we go to the 'error' label and leave the function without
> ever calling fclose(f).
> 
>> +}
> 
> thanks
> -- PMM
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-09-10  7:21 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03 13:35 [Qemu-devel] [PULL v2 00/16] Block patches Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 01/16] qemu-io: add pattern file for write command Max Reitz
2019-09-09 17:26   ` Peter Maydell
2019-09-10  7:19     ` Max Reitz [this message]
2019-09-10  7:23       ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2019-09-10  7:59         ` Denis Plotnikov
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 02/16] block: fix permission update in bdrv_replace_node Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 03/16] block: posix: Always allocate the first block Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 04/16] iotests: Test allocate_first_block() with O_DIRECT Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 05/16] iotests: Fix _filter_img_create() Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 06/16] vmdk: Use bdrv_dirname() for relative extent paths Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 07/16] iotests: Keep testing broken " Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 08/16] vmdk: Reject invalid compressed writes Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 09/16] iotests: Disable broken streamOptimized tests Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 10/16] iotests: Disable 110 for vmdk.twoGbMaxExtentSparse Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 11/16] iotests: Disable 126 for flat vmdk subformats Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 12/16] file-posix: fix request_alignment typo Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 13/16] iotests: Add -display none to the qemu options Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 14/16] iotests: Check for enabled drivers before testing them Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 15/16] tests/check-block: Skip iotests when sanitizers are enabled Max Reitz
2019-09-03 13:35 ` [Qemu-devel] [PULL v2 16/16] iotests: Unify cache mode quoting Max Reitz
2019-09-04 12:58 ` [Qemu-devel] [PULL v2 00/16] Block patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3311e590-d2c1-2388-27cf-981c917881ab@redhat.com \
    --to=mreitz@redhat.com \
    --cc=dplotnikov@virtuozzo.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.