qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] hw/bt/sdp: Fix resource leak detect by coverity


From: Stefan Weil
Subject: Re: [Qemu-devel] [PATCH] hw/bt/sdp: Fix resource leak detect by coverity
Date: Sat, 14 Mar 2015 11:07:33 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0

Am 14.03.2015 um 10:47 schrieb Shannon Zhao:
Free data in function sdp_attr_write after use.

Signed-off-by: Shannon Zhao <address@hidden>
Signed-off-by: Shannon Zhao <address@hidden>
---
     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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]