From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWiyq-0005wA-DR for qemu-devel@nongnu.org; Sat, 14 Mar 2015 06:07:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWiyn-0002bR-6x for qemu-devel@nongnu.org; Sat, 14 Mar 2015 06:07:40 -0400 Message-ID: <55040865.8050908@weilnetz.de> Date: Sat, 14 Mar 2015 11:07:33 +0100 From: Stefan Weil MIME-Version: 1.0 References: <1426326454-7216-1-git-send-email-zhaoshenglong@huawei.com> In-Reply-To: <1426326454-7216-1-git-send-email-zhaoshenglong@huawei.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] hw/bt/sdp: Fix resource leak detect by coverity List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Shannon Zhao , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, hangaohuai@huawei.com, qemu-trivial@nongnu.org, mjt@tls.msk.ru, peter.huangpeng@huawei.com, shannon.zhao@linaro.org, pbonzini@redhat.com Am 14.03.2015 um 10:47 schrieb Shannon Zhao: > Free data in function sdp_attr_write after use. > > Signed-off-by: Shannon Zhao > Signed-off-by: Shannon Zhao > --- > For minimum modification, just add a variable to record the data. > --- > hw/bt/sdp.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/hw/bt/sdp.c b/hw/bt/sdp.c > index 218e075..8be0d14 100644 > --- a/hw/bt/sdp.c > +++ b/hw/bt/sdp.c > @@ -698,7 +698,7 @@ static void sdp_service_record_build(struct sdp_service_record_s *record, > struct sdp_def_service_s *def, int handle) > { > int len = 0; > - uint8_t *data; > + uint8_t *data, *pt; > int *uuid; > > record->uuids = 0; > @@ -712,7 +712,7 @@ static void sdp_service_record_build(struct sdp_service_record_s *record, > g_malloc0(record->attributes * sizeof(*record->attribute_list)); > record->uuid = > g_malloc0(record->uuids * sizeof(*record->uuid)); > - data = g_malloc(len); > + pt = data = g_malloc(len); > > record->attributes = 0; > uuid = record->uuid; > @@ -735,6 +735,7 @@ static void sdp_service_record_build(struct sdp_service_record_s *record, > record->attribute_list[record->attributes ++].len = len; > data += len; > } > + g_free(pt); > > /* Sort the attribute list by the AttributeID */ > qsort(record->attribute_list, record->attributes, This fixes the memory leak, but I still don't understand what is done here. data is allocated, then filled with values, now it is also deallocated. But I'm missing the part where all those data is used. Stefan