From e0e6a5e50ef8c342f5ce759ceb6c63b90745dd5c Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Sun, 27 Mar 2011 22:48:15 -0700 Subject: [PATCH] Fixed leak in update handler. --- protocols/vnc/src/vnc_client.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/protocols/vnc/src/vnc_client.c b/protocols/vnc/src/vnc_client.c index 404241d2..280206ea 100644 --- a/protocols/vnc/src/vnc_client.c +++ b/protocols/vnc/src/vnc_client.c @@ -156,20 +156,21 @@ void guac_vnc_cursor(rfbClient* client, int x, int y, int w, int h, int bpp) { void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { - int dx, dy; - guac_client* gc = rfbClientGetClientData(client, __GUAC_CLIENT); GUACIO* io = gc->io; + int dx, dy; + /* Cairo image buffer */ - int stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w); - unsigned char* buffer = malloc(h*stride); - unsigned char* buffer_row_current = buffer; + int stride; + unsigned char* buffer; + unsigned char* buffer_row_current; cairo_surface_t* surface; - unsigned int bpp = client->format.bitsPerPixel/8; - unsigned int fb_stride = bpp * client->width; - unsigned char* fb_row_current = client->frameBuffer + (y * fb_stride) + (x * bpp); + /* VNC framebuffer */ + unsigned int bpp; + unsigned int fb_stride; + unsigned char* fb_row_current; /* Ignore extra update if already handled by copyrect */ if (((vnc_guac_client_data*) gc->data)->copy_rect_used) { @@ -177,6 +178,15 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { return; } + /* Init Cairo buffer */ + stride = cairo_format_stride_for_width(CAIRO_FORMAT_RGB24, w); + buffer = malloc(h*stride); + buffer_row_current = buffer; + + bpp = client->format.bitsPerPixel/8; + fb_stride = bpp * client->width; + fb_row_current = client->frameBuffer + (y * fb_stride) + (x * bpp); + /* Copy image data from VNC client to PNG */ for (dy = y; dy