summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordscho <dscho>2003-07-29 15:02:33 +0000
committerdscho <dscho>2003-07-29 15:02:33 +0000
commit964aa1628f2cc4fac17c22dc89fc2439bd87b00e (patch)
treefbb5a0eacfd5ab9f1c84a0825744b5e69364eba5
parent9b46601daa37906feb3c2334200170e53486cdac (diff)
downloadlibtdevnc-964aa1628f2cc4fac17c22dc89fc2439bd87b00e.tar.gz
libtdevnc-964aa1628f2cc4fac17c22dc89fc2439bd87b00e.zip
further valgrinding showed leaked mallocs
-rw-r--r--cursor.c31
-rw-r--r--libvncclient/client_test.c44
-rw-r--r--libvncclient/rfbproto.c8
-rw-r--r--libvncclient/vncviewer.c4
-rw-r--r--main.c15
-rw-r--r--rfb/rfb.h2
-rw-r--r--rfb/rfbclient.h1
-rw-r--r--test/tight-1.c9
-rw-r--r--tight.c11
9 files changed, 101 insertions, 24 deletions
diff --git a/cursor.c b/cursor.c
index 786ee02..42c4eb3 100644
--- a/cursor.c
+++ b/cursor.c
@@ -258,12 +258,14 @@ rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskSt
char* cp;
unsigned char bit;
+ cursor->cleanup=TRUE;
cursor->width=width;
cursor->height=height;
/*cursor->backRed=cursor->backGreen=cursor->backBlue=0xffff;*/
cursor->foreRed=cursor->foreGreen=cursor->foreBlue=0xffff;
cursor->source = (unsigned char*)calloc(w,height);
+ cursor->cleanupSource = TRUE;
for(j=0,cp=cursorString;j<height;j++)
for(i=0,bit=0x80;i<width;i++,bit=(bit&1)?0x80:bit>>1,cp++)
if(*cp!=' ') cursor->source[j*w+i/8]|=bit;
@@ -275,6 +277,7 @@ rfbCursorPtr rfbMakeXCursor(int width,int height,char* cursorString,char* maskSt
if(*cp!=' ') cursor->mask[j*w+i/8]|=bit;
} else
cursor->mask = (unsigned char*)rfbMakeMaskForXCursor(width,height,(char*)cursor->source);
+ cursor->cleanupMask = TRUE;
return(cursor);
}
@@ -305,11 +308,19 @@ char* rfbMakeMaskForXCursor(int width,int height,char* source)
void rfbFreeCursor(rfbCursorPtr cursor)
{
if(cursor) {
- if(cursor->richSource)
- free(cursor->richSource);
- free(cursor->source);
- free(cursor->mask);
- free(cursor);
+ if(cursor->cleanupRichSource && cursor->richSource)
+ free(cursor->richSource);
+ if(cursor->cleanupSource && cursor->source)
+ free(cursor->source);
+ if(cursor->cleanupMask && cursor->mask)
+ free(cursor->mask);
+ if(cursor->cleanup)
+ free(cursor);
+ else {
+ cursor->cleanup=cursor->cleanupSource=cursor->cleanupMask
+ =cursor->cleanupRichSource=FALSE;
+ cursor->source=cursor->mask=cursor->richSource=0;
+ }
}
}
@@ -323,8 +334,11 @@ void MakeXCursorFromRichCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor)
uint32_t background;
char *back=(char*)&background;
unsigned char bit;
-
+
+ if(cursor->source && cursor->cleanupSource)
+ free(cursor->source);
cursor->source=(unsigned char*)calloc(w,cursor->height);
+ cursor->cleanupSource=TRUE;
if(format->bigEndian)
back+=4-bpp;
@@ -347,7 +361,10 @@ void MakeRichCursorFromXCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr cursor)
unsigned char *cp;
unsigned char bit;
+ if(cursor->richSource && cursor->cleanupRichSource)
+ free(cursor->richSource);
cp=cursor->richSource=(unsigned char*)calloc(cursor->width*bpp,cursor->height);
+ cursor->cleanupRichSource=TRUE;
if(format->bigEndian) {
back+=4-bpp;
@@ -494,7 +511,7 @@ void rfbSetCursor(rfbScreenInfoPtr rfbScreen,rfbCursorPtr c,Bool freeOld)
LOCK(rfbScreen->cursorMutex);
}
- if(freeOld && rfbScreen->cursor)
+ if(rfbScreen->cursor && (freeOld || rfbScreen->cursor->cleanup))
rfbFreeCursor(rfbScreen->cursor);
rfbScreen->cursor = c;
diff --git a/libvncclient/client_test.c b/libvncclient/client_test.c
index 94f6f58..16429b0 100644
--- a/libvncclient/client_test.c
+++ b/libvncclient/client_test.c
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <errno.h>
#include <rfb/rfbclient.h>
void PrintRect(rfbClient* client, int x, int y, int w, int h) {
@@ -39,14 +40,33 @@ void SaveFramebufferAsPGM(rfbClient* client, int x, int y, int w, int h) {
fputc(client->frameBuffer[j+i+bpp-2],f);
fputc(client->frameBuffer[j+i+bpp-3],f);
} else {
- fputc(client->frameBuffer[j+i+bpp+0],f);
- fputc(client->frameBuffer[j+i+bpp+1],f);
- fputc(client->frameBuffer[j+i+bpp+2],f);
+ fputc(client->frameBuffer[j+i+0],f);
+ fputc(client->frameBuffer[j+i+1],f);
+ fputc(client->frameBuffer[j+i+2],f);
}
}
fclose(f);
}
+int WaitForMessage(rfbClient* client,unsigned int usecs)
+{
+ fd_set fds;
+ struct timeval timeout;
+ int num;
+
+ timeout.tv_sec=(usecs/1000000);
+ timeout.tv_usec=(usecs%1000000);
+
+ FD_ZERO(&fds);
+ FD_SET(client->sock,&fds);
+
+ num=select(client->sock+1, &fds, NULL, NULL, &timeout);
+ if(num<0)
+ rfbClientLog("Waiting for message failed: %d (%s)\n",errno,strerror(errno));
+
+ return num;
+}
+
int
main(int argc, char **argv)
{
@@ -54,9 +74,10 @@ main(int argc, char **argv)
rfbClient* client = rfbGetClient(&argc,argv,8,3,4);
const char* vncServerHost="";
int vncServerPort=5900;
+ time_t t=time(0);
client->GotFrameBufferUpdate = PrintRect;
- client->GotFrameBufferUpdate = SaveFramebufferAsPGM;
+ //client->GotFrameBufferUpdate = SaveFramebufferAsPGM;
/* The -listen option is used to make us a daemon process which listens for
incoming connections from servers, rather than actively connecting to a
@@ -86,13 +107,22 @@ main(int argc, char **argv)
}
client->appData.encodingsString="tight";
- rfbInitClient(client,vncServerHost,vncServerPort);
+ if(!rfbInitClient(client,vncServerHost,vncServerPort)) {
+ rfbClientCleanup(client);
+ return 1;
+ }
- while (1) {
- if (!HandleRFBServerMessage(client))
+ while (time(0)-t<5) {
+ static int i=0;
+ fprintf(stderr,"\r%d",i++);
+ if(WaitForMessage(client,500)<0)
+ break;
+ if(!HandleRFBServerMessage(client))
break;
}
+ rfbClientCleanup(client);
+
return 0;
}
diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c
index 389aa05..72d71d4 100644
--- a/libvncclient/rfbproto.c
+++ b/libvncclient/rfbproto.c
@@ -979,10 +979,10 @@ PrintPixelFormat(format)
(format->bigEndian ? "Most" : "Least"));
}
if (format->trueColour) {
- rfbClientLog(" TRUE colour: max red %d green %d blue %d",
- format->redMax, format->greenMax, format->blueMax);
- rfbClientLog(", shift red %d green %d blue %d\n",
- format->redShift, format->greenShift, format->blueShift);
+ rfbClientLog(" TRUE colour: max red %d green %d blue %d"
+ ", shift red %d green %d blue %d\n",
+ format->redMax, format->greenMax, format->blueMax,
+ format->redShift, format->greenShift, format->blueShift);
} else {
rfbClientLog(" Colour map (not true colour).\n");
}
diff --git a/libvncclient/vncviewer.c b/libvncclient/vncviewer.c
index c5f7c69..54fcb51 100644
--- a/libvncclient/vncviewer.c
+++ b/libvncclient/vncviewer.c
@@ -121,3 +121,7 @@ Bool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerPort
return TRUE;
}
+
+void rfbClientCleanup(rfbClient* client) {
+ free(client);
+}
diff --git a/main.c b/main.c
index e112b5b..9a34290 100644
--- a/main.c
+++ b/main.c
@@ -404,6 +404,7 @@ void defaultSetXCutText(char* text, int len, rfbClientPtr cl)
#if defined(WIN32) || defined(sparc) || !defined(NO_STRICT_ANSI)
static rfbCursor myCursor =
{
+ FALSE, FALSE, FALSE, FALSE,
(unsigned char*)"\000\102\044\030\044\102\000",
(unsigned char*)"\347\347\176\074\176\347\347",
8, 7, 3, 3,
@@ -414,14 +415,13 @@ static rfbCursor myCursor =
#else
static rfbCursor myCursor =
{
+ cleanup: FALSE,
+ cleanupSource: FALSE,
+ cleanupMask: FALSE,
+ cleanupRichSource: FALSE,
source: "\000\102\044\030\044\102\000",
mask: "\347\347\176\074\176\347\347",
width: 8, height: 7, xhot: 3, yhot: 3,
- /*
- width: 8, height: 7, xhot: 0, yhot: 0,
- source: "\000\074\176\146\176\074\000",
- mask: "\176\377\377\377\377\377\176",
- */
foreRed: 0, foreGreen: 0, foreBlue: 0,
backRed: 0xffff, backGreen: 0xffff, backBlue: 0xffff,
richSource: 0
@@ -713,6 +713,8 @@ void rfbNewFramebuffer(rfbScreenInfoPtr rfbScreen, char *framebuffer,
rfbReleaseClientIterator(iterator);
}
+extern void TightCleanup();
+
void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen)
{
rfbClientIteratorPtr i=rfbGetClientIterator(rfbScreen);
@@ -729,7 +731,10 @@ void rfbScreenCleanup(rfbScreenInfoPtr rfbScreen)
FREE_IF(colourMap.data.bytes);
FREE_IF(underCursorBuffer);
TINI_MUTEX(rfbScreen->cursorMutex);
+ if(rfbScreen->cursor)
+ rfbFreeCursor(rfbScreen->cursor);
free(rfbScreen);
+ TightCleanup();
}
void rfbInitServer(rfbScreenInfoPtr rfbScreen)
diff --git a/rfb/rfb.h b/rfb/rfb.h
index fa66916..7acec11 100644
--- a/rfb/rfb.h
+++ b/rfb/rfb.h
@@ -635,6 +635,8 @@ extern Bool rfbSendRectEncodingTight(rfbClientPtr cl, int x,int y,int w,int h);
/* cursor.c */
typedef struct rfbCursor {
+ /* set this to true if LibVNCServer has to free this cursor */
+ Bool cleanup, cleanupSource, cleanupMask, cleanupRichSource;
unsigned char *source; /* points to bits */
unsigned char *mask; /* points to bits */
unsigned short width, height, xhot, yhot; /* metrics */
diff --git a/rfb/rfbclient.h b/rfb/rfbclient.h
index c08f3a5..d1b12dd 100644
--- a/rfb/rfbclient.h
+++ b/rfb/rfbclient.h
@@ -189,3 +189,4 @@ extern Bool SameMachine(int sock);
/* vncviewer.c */
rfbClient* rfbGetClient(int* argc,char** argv,int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
Bool rfbInitClient(rfbClient* client,const char* vncServerHost,int vncServerPort);
+void rfbClientCleanup(rfbClient* client);
diff --git a/test/tight-1.c b/test/tight-1.c
index 825ca83..987d481 100644
--- a/test/tight-1.c
+++ b/test/tight-1.c
@@ -1,9 +1,11 @@
+#include <time.h>
#include <rfb/rfb.h>
#include <rfb/rfbclient.h>
int main(int argc,char** argv)
{
int i,j;
+ time_t t=time(0);
rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4);
rfbClient* client=rfbGetClient(&argc,argv,8,3,4);
@@ -13,7 +15,7 @@ int main(int argc,char** argv)
server->frameBuffer[j]=j;
//server->maxRectsPerUpdate=-1;
rfbInitServer(server);
- while(1) {
+ while(time(0)-t<20) {
for(j=0;j<400;j+=10)
for(i=0;i<300;i+=10)
@@ -21,5 +23,10 @@ int main(int argc,char** argv)
rfbProcessEvents(server,5000);
}
+
+ free(server->frameBuffer);
+ rfbScreenCleanup(server);
+ rfbClientCleanup(client);
+
return(0);
}
diff --git a/tight.c b/tight.c
index 4bbdd11..05e7aed 100644
--- a/tight.c
+++ b/tight.c
@@ -115,6 +115,17 @@ static char *tightAfterBuf = NULL;
static int *prevRowBuf = NULL;
+void TightCleanup()
+{
+ if(tightBeforeBufSize) {
+ free(tightBeforeBuf);
+ tightBeforeBufSize=0;
+ }
+ if(tightAfterBufSize) {
+ free(tightAfterBuf);
+ tightAfterBufSize=0;
+ }
+}
/* Prototypes for static functions. */