Skip to contentSkip to conversation

vhost: fix a memory leak

PATCH In review Peng Hao 3 participants 5 messages Jul 4, 2017

lore
Share & tools
lore

Peng Hao

author
#0 lore raw

PATCH 1/1 vhost: fix a memory leak

vhost exists a call for g_file_get_contents, but not call g_free.

---
 hw/virtio/vhost-backend.c | 2 ++
 1 file changed, 2 insertions(+)
hw/virtio/vhost-backend.c +2 -0
index 4e31de1..2c481d6 100644
@@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
                             &s, NULL, NULL)) {
         uint64_t val = g_ascii_strtoull(s, NULL, 10);
         if (!((val == G_MAXUINT64 || !val) && errno)) {
+            g_free(s);
             return val;
         }
         error_report("ignoring invalid max_mem_regions value in vhost module:"
                      " %s", s);
     }
+    g_free(s);
     return limit;
 }
 
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 4 lines · Peng Hao

vhost exists a call for g_file_get_contents, but not call g_free.

---

Quoted 21 lines
 hw/virtio/vhost-backend.c | 2 ++
 1 file changed, 2 insertions(+)
hw/virtio/vhost-backend.c +1 -0
index 4e31de1..2c481d6 100644
@@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct
 vhost_dev *dev)
                             &s, NULL, NULL)) {
         uint64_t val = g_ascii_strtoull(s, NULL, 10);
         if (!((val == G_MAXUINT64 || !val) && errno)) {
+            g_free(s);
             return val;
         }
         error_report("ignoring invalid max_mem_regions value in vhost

module:"

                      " %s", s);
     }
+    g_free(s);
     return limit;
Quoted 8 lines

}

--
1.8.3.1

--

Marc-André Lureau

#2 lore raw
Quoted 30 lines · Marc-André Lureau

Hi

On Tue, Jul 4, 2017 at 4:16 PM Peng Hao <[email protected]> wrote:

vhost exists a call for g_file_get_contents, but not call g_free.

    ---
     hw/virtio/vhost-backend.c | 2 ++
     1 file changed, 2 insertions(+)

    diff --git a/hw/virtio/vhost-backend.c b/hw/virtio/vhost-backend.c
    index 4e31de1..2c481d6 100644
    --- a/hw/virtio/vhost-backend.c
    +++ b/hw/virtio/vhost-backend.c
    @@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev
    *dev)
                                 &s, NULL, NULL)) {
             uint64_t val = g_ascii_strtoull(s, NULL, 10);
             if (!((val == G_MAXUINT64 || !val) && errno)) {
    +            g_free(s);
                 return val;
             }
             error_report("ignoring invalid max_mem_regions value in vhost
    module:"
Quoted 9 lines
                          " %s", s);
         }
    +    g_free(s);
         return limit;
     }

    --
    1.8.3.1

Thanks for the review.
I'd like to include your tag in commit log.
For that, could you please repost your ack in text format using some other mail client?
My scripts don't handle the way your mail client scrambles text.

Quoted 4 lines

--
Marc-André Lureau

Reviewed-by on v1 1/1
#3 lore raw
In reply to Peng Hao

Hi

Quoted 3 lines · Peng Hao

vhost exists a call for g_file_get_contents, but not call g_free.

mst: is this better?

Quoted 27 lines
---
 hw/virtio/vhost-backend.c | 2 ++
 1 file changed, 2 insertions(+)
hw/virtio/vhost-backend.c +2 -1
index 4e31de1..2c481d6 100644
@@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
                             &s, NULL, NULL)) {
         uint64_t val = g_ascii_strtoull(s, NULL, 10);
         if (!((val == G_MAXUINT64 || !val) && errno)) {
+            g_free(s);
             return val;
         }
         error_report("ignoring invalid max_mem_regions value in vhost module:"
                      " %s", s);
     }
+    g_free(s);
     return limit;
 }
 
--

1.8.3.1

Signature · 1 line
Marc-André Lureau
#4 lore raw
Quoted 10 lines · Marc-André Lureau

Hi

Quoted 3 lines · Peng Hao

vhost exists a call for g_file_get_contents, but not call g_free.

mst: is this better?

That's fine, thanks!

Quoted 32 lines
Quoted 27 lines
---
 hw/virtio/vhost-backend.c | 2 ++
 1 file changed, 2 insertions(+)
hw/virtio/vhost-backend.c +2 -1
index 4e31de1..2c481d6 100644
@@ -52,11 +52,13 @@ static int vhost_kernel_memslots_limit(struct vhost_dev *dev)
                             &s, NULL, NULL)) {
         uint64_t val = g_ascii_strtoull(s, NULL, 10);
         if (!((val == G_MAXUINT64 || !val) && errno)) {
+            g_free(s);
             return val;
         }
         error_report("ignoring invalid max_mem_regions value in vhost module:"
                      " %s", s);
     }
+    g_free(s);
     return limit;
 }
 
--

1.8.3.1

Signature · 1 line
Marc-André Lureau