Skip to contentSkip to conversation

VNC: Fix memory allocation (wrong structure size).

PATCH In review Stefan Weil 2 participants 2 messages May 24, 2009 – May 27, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 VNC: Fix memory allocation (wrong structure size).

Pointer vs addresses a VncDisplay structure, so it is sufficient to allocate sizeof(VncDisplay) or sizeof(*vs) bytes instead of the much larger sizeof(VncState).

Maybe the misleading name should be fixed, too:
the code contains many places where vs is used, sometimes it is a VncState *, sometimes it is a VncDisplay *. vd would be a better name.

---
 vnc.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
vnc.c +1 -2
index 3f5d622..41defc2 100644
@@ -2033,9 +2033,8 @@ static void vnc_listen_read(void *opaque)
 
 void vnc_display_init(DisplayState *ds)
 {
-    VncDisplay *vs;
+    VncDisplay *vs = qemu_mallocz(sizeof(*vs));
 
-    vs = qemu_mallocz(sizeof(VncState));
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
 
     ds->opaque = vs;

--
1.5.6.5

#1 lore raw
Quoted 31 lines · Stefan Weil

Pointer vs addresses a VncDisplay structure, so it is sufficient to allocate sizeof(VncDisplay) or sizeof(*vs) bytes instead of the much larger sizeof(VncState).

Maybe the misleading name should be fixed, too:
the code contains many places where vs is used, sometimes it is a VncState *, sometimes it is a VncDisplay *. vd would be a better name.

---
 vnc.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
vnc.c +1 -3
index 3f5d622..41defc2 100644
@@ -2033,9 +2033,8 @@ static void vnc_listen_read(void *opaque)
 
 void vnc_display_init(DisplayState *ds)
 {
-    VncDisplay *vs;
+    VncDisplay *vs = qemu_mallocz(sizeof(*vs));
 
-    vs = qemu_mallocz(sizeof(VncState));
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
 
     ds->opaque = vs;
--
Quoted 4 lines

1.5.6.5

The patch above was whitespace broken.
The appended patch will work.

Regards,

Stefan Weil

Quoted 1 line

From 1bcb958ac2127f96a8c3ee7fefa341f7296e48ba Mon Sep 17 00:00:00 2001

From: Stefan Weil <[email protected]>
Date: Sun, 24 May 2009 22:25:44 +0200
Subject: [PATCH] VNC: Fix memory allocation (wrong structure size).

Pointer vs addresses a VncDisplay structure, so it is sufficient to allocate sizeof(VncDisplay) or sizeof(*vs) bytes instead of the much larger sizeof(VncState).

Maybe the misleading name should be fixed, too:
the code contains many places where vs is used, sometimes it is a VncState *, sometimes it is a VncDisplay *. vd would be a better name.

---
 vnc.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
vnc.c +1 -2
index 3f5d622..41defc2 100644
@@ -2033,9 +2033,8 @@ static void vnc_listen_read(void *opaque)
 
 void vnc_display_init(DisplayState *ds)
 {
-    VncDisplay *vs;
+    VncDisplay *vs = qemu_mallocz(sizeof(*vs));
 
-    vs = qemu_mallocz(sizeof(VncState));
     dcl = qemu_mallocz(sizeof(DisplayChangeListener));
 
     ds->opaque = vs;
Signature · 1 line
1.5.6.5