Further cleanup, fixed bad alloc.

This commit is contained in:
Michael Jumper
2010-09-06 16:55:58 -07:00
parent f20fa375ad
commit 106df930d6
2 changed files with 36 additions and 19 deletions

View File

@@ -3,8 +3,6 @@
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <png.h>
#include "guacio.h" #include "guacio.h"
char __GUACIO_BAS64_CHARACTERS[64] = { char __GUACIO_BAS64_CHARACTERS[64] = {

View File

@@ -12,17 +12,17 @@
char __guac_password[] = "potato"; char __guac_password[] = "potato";
char* __GUAC_VNC_TAG_IO = "GUACIO"; char* __GUAC_VNC_TAG_IO = "GUACIO";
char* __GUAC_VNC_TAG_PNG_ROWS = "PNG_ROWS"; char* __GUAC_VNC_TAG_PNG_BUFFER = "PNG_BUFFER";
void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) { void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) {
int dx, dy; int dx, dy;
GUACIO* io = rfbClientGetClientData(client, __GUAC_VNC_TAG_IO); GUACIO* io = rfbClientGetClientData(client, __GUAC_VNC_TAG_IO);
png_byte** png_rows = rfbClientGetClientData(client, __GUAC_VNC_TAG_PNG_ROWS); png_byte** png_buffer = rfbClientGetClientData(client, __GUAC_VNC_TAG_PNG_BUFFER);
png_byte* row; png_byte* row;
png_byte** png_row_current = png_rows; png_byte** png_row_current = png_buffer;
unsigned int bpp = client->format.bitsPerPixel/8; unsigned int bpp = client->format.bitsPerPixel/8;
unsigned int bytesPerRow = bpp * client->width; unsigned int bytesPerRow = bpp * client->width;
@@ -62,7 +62,7 @@ void guac_vnc_update(rfbClient* client, int x, int y, int w, int h) {
} }
} }
guac_send_png(io, x, y, png_rows, w, h); guac_send_png(io, x, y, png_buffer, w, h);
guac_flush(io); guac_flush(io);
} }
@@ -87,15 +87,41 @@ char* guac_vnc_get_password(rfbClient* client) {
return password; return password;
} }
png_byte** guac_alloc_png_buffer(int w, int h) {
png_byte** png_buffer;
png_byte* row;
int y;
/* Allocate rows for PNG */
png_buffer = (png_byte**) malloc(h * sizeof(png_byte*));
for (y=0; y<h; y++) {
row = (png_byte*) malloc(sizeof(png_byte) * 3 * w);
png_buffer[y] = row;
}
return png_buffer;
}
void guac_free_png_buffer(png_byte** png_buffer, int h) {
int y;
/* Free PNG data */
for (y = 0; y<h; y++)
free(png_buffer[y]);
free(png_buffer);
}
void proxy(int client_fd) { void proxy(int client_fd) {
char* hostname; char* hostname;
int wait_result; int wait_result;
rfbClient* rfb_client; rfbClient* rfb_client;
png_byte** png_rows; png_byte** png_buffer;
png_byte* row;
int y;
GUACIO* io = guac_open(client_fd); GUACIO* io = guac_open(client_fd);
@@ -120,16 +146,11 @@ void proxy(int client_fd) {
fprintf(stderr, "SUCCESS.\n"); fprintf(stderr, "SUCCESS.\n");
} }
/* Allocate rows for PNG */ png_buffer = guac_alloc_png_buffer(rfb_client->width, rfb_client->height);
png_rows = (png_byte**) malloc(rfb_client->height * sizeof(png_byte*));
for (y=0; y<rfb_client->width; y++) {
row = (png_byte*) malloc(sizeof(png_byte) * 3 * rfb_client->width);
png_rows[y] = row;
}
/* Store Guac data in client */ /* Store Guac data in client */
rfbClientSetClientData(rfb_client, __GUAC_VNC_TAG_IO, io); rfbClientSetClientData(rfb_client, __GUAC_VNC_TAG_IO, io);
rfbClientSetClientData(rfb_client, __GUAC_VNC_TAG_PNG_ROWS, png_rows); rfbClientSetClientData(rfb_client, __GUAC_VNC_TAG_PNG_BUFFER, png_buffer);
/* Send name */ /* Send name */
guac_send_name(io, rfb_client->desktopName); guac_send_name(io, rfb_client->desktopName);
@@ -158,9 +179,7 @@ void proxy(int client_fd) {
} }
/* Free PNG data */ /* Free PNG data */
for (y = 0; y<rfb_client->height; y++) guac_free_png_buffer(png_buffer, rfb_client->height);
free(png_rows[y]);
free(png_rows);
/* Clean up VNC client*/ /* Clean up VNC client*/