[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-trivial] [Qemu-devel] [PATCH] rdma: fix memory leak
From: |
Gonglei |
Subject: |
Re: [Qemu-trivial] [Qemu-devel] [PATCH] rdma: fix memory leak |
Date: |
Tue, 23 Jun 2015 17:32:25 +0800 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
On 2015/6/23 17:20, Markus Armbruster wrote:
> Markus Armbruster <address@hidden> writes:
>
>> <address@hidden> writes:
>>
>>> From: Gonglei <address@hidden>
>>>
>>> Variable "r" going out of scope leaks the storage
>>> it points to in line 3268.
>>>
>>> Signed-off-by: Gonglei <address@hidden>
>>> ---
>>> migration/rdma.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/migration/rdma.c b/migration/rdma.c
>>> index cf5de7e..de80860 100644
>>> --- a/migration/rdma.c
>>> +++ b/migration/rdma.c
>>> @@ -3262,12 +3262,13 @@ static const QEMUFileOps rdma_write_ops = {
>>>
>>> static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
>>> {
>>> - QEMUFileRDMA *r = g_malloc0(sizeof(QEMUFileRDMA));
>>> + QEMUFileRDMA *r = NULL;
>>
>> Dead initialization, please drop.
>>
>>>
>>> if (qemu_file_mode_is_not_valid(mode)) {
>>> return NULL;
>>> }
>>>
>>> + r = g_malloc0(sizeof(QEMUFileRDMA));
>>> r->rdma = rdma;
>>>
>>> if (mode[0] == 'w') {
>>
>> Looks good otherwise.
>
> Since you're touching this, you could
>
> r = g_new0(QEMUFileRDMA, 1)
>
> See commit 5839e53.
>
I noticed this, but this whole file is using g_malloc, maybe using
another patch fix them is better. This path is just fix memory leak. :)
Regards,
-Gonglei