Skip to contentSkip to conversation

severe memory leak caused by broken palette_destroy() function

PATCH Applied Ulrich Obergfell 4 participants 4 messages Mar 25, 2011 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): 942456759.505022.1301042552254.JavaMail.root@zmail07.collab.prod.int.phx2.redhat.com

#1 lore raw

PATCH v2 1/1 severe memory leak caused by broken palette_destroy() function

This is version 2 of the patch that I originally posted in:

http://lists.gnu.org/archive/html/qemu-devel/2011-03/msg02063.html

[Sorry, I missed to include the keyword 'PATCH' in the subject
of the original post.]

The following commit breaks the code of the function palette_destroy().

http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e31e3694afef58ba191cbcc6875ec243e5971268

The broken code causes a severe memory leak of 'VncPalette' structures because it never frees anything:

     70 void palette_destroy(VncPalette *palette)
     71 {
     72     if (palette == NULL) {
     73         qemu_free(palette);
     74     }
     75 }

Version 2 of the patch calls qemu_free() unconditionally.

ui/vnc-palette.c renamed from ui/vnc-palette.c.orig0 +1 -3
diff -up ./ui/vnc-palette.c.orig0 ./ui/vnc-palette.c
@@ -69,9 +69,7 @@ void palette_init(VncPalette *palette, s
 
 void palette_destroy(VncPalette *palette)
 {
-    if (palette == NULL) {
-        qemu_free(palette);
-    }
+    qemu_free(palette);
 }
 
 int palette_put(VncPalette *palette, uint32_t color)
Reviewed-by on v2 1/1
#2 lore raw
Quoted 21 lines · Ulrich Obergfell

This is version 2 of the patch that I originally posted in:

http://lists.gnu.org/archive/html/qemu-devel/2011-03/msg02063.html

[Sorry, I missed to include the keyword 'PATCH' in the subject
of the original post.]

The following commit breaks the code of the function palette_destroy().

http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e31e3694afef58ba191cbcc6875ec243e5971268

The broken code causes a severe memory leak of 'VncPalette' structures because it never frees anything:

     70 void palette_destroy(VncPalette *palette)
     71 {
     72     if (palette == NULL) {
     73         qemu_free(palette);
     74     }
     75 }
Quoted 3 lines

Version 2 of the patch calls qemu_free() unconditionally.

Ouchhhhhhhhhhhhhhh

A new reason to never ever test if pointer is != NULL before calling free.

Good catch.

Reviewed-by on v2 1/1
#3 lore raw
In reply to Ulrich Obergfell
Quoted 22 lines · Ulrich Obergfell

This is version 2 of the patch that I originally posted in:

http://lists.gnu.org/archive/html/qemu-devel/2011-03/msg02063.html

[Sorry, I missed to include the keyword 'PATCH' in the subject of the original post.]

The following commit breaks the code of the function palette_destroy().

http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e31e3694afef58ba191cbcc6875ec243e5971268

The broken code causes a severe memory leak of 'VncPalette' structures because it never frees anything:

    70 void palette_destroy(VncPalette *palette)
    71 {
    72     if (palette == NULL) {
    73         qemu_free(palette);
    74     }
    75 }

Quoted 3 lines

Version 2 of the patch calls qemu_free() unconditionally.

Looks good.

#4 lore raw
Quoted 22 lines · Stefan Hajnoczi
Quoted 21 lines · Ulrich Obergfell

This is version 2 of the patch that I originally posted in:

http://lists.gnu.org/archive/html/qemu-devel/2011-03/msg02063.html

[Sorry, I missed to include the keyword 'PATCH' in the subject
of the original post.]

The following commit breaks the code of the function palette_destroy().

http://git.kernel.org/?p=virt/kvm/qemu-kvm.git;a=commit;h=e31e3694afef58ba191cbcc6875ec243e5971268

The broken code causes a severe memory leak of 'VncPalette' structures because it never frees anything:

     70 void palette_destroy(VncPalette *palette)
     71 {
     72     if (palette == NULL) {
     73         qemu_free(palette);
     74     }
     75 }
Quoted 4 lines
Quoted 3 lines

Version 2 of the patch calls qemu_free() unconditionally.

Looks good.

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 1 line