WinVNC 3.3.3r9 Memory Leak

Steve Daly list "at"
Mon, 14 Jan 2002 11:47:48 +0000

I think I've found a memory leak with WinVNC 3.3.3r9 (and some earlier
versions) when running on clean Windows 95 installations.

I look after a number of Win95 machines running control system applications.
They need to run for many months unattended, which they generally manage
without problems, but recently I have been noticing that some of them were
failing with "out of disk space" errors caused by excessive swap-file usage
(over 1Gb swapfile on many occasions).  Running a process viewer showed that
WinVNC had huge amounts of memory allocated to it (proportional to machine
uptime). I had a browse through the vnc-list and found a couple of references
to the problem, but nothing definite regarding the cause.

Using memory viewers I found that WinVNC leaks 256 bytes every 5 seconds when
running on Win95 (Win98 and NT4.SP6 are OK).  In each case, the 256 byte block
contains some unidentified bytes, and an ascii string containing the machine
hostname.  Looking at the source, I guessed that this is a problem with the
gethostname() call in GetIPAddrString() in vncMenu.cpp, which updates the
systray icon and the associated tooltip containing the machine IP address
every 5 seconds.  Browsing the newsgroups it seems that the winsock
gethostname() call is known to leak memory in Winsock 1.1 (as supplied with
all releases of Win95).  Sure enough, installing the MS WinSock2 upgrade stops
the memory leak.

A workaround for Win95 use is to install the Winsock2 Upgrade.
It would obviously be better to modify WinVNC so that it will work on all
Winsock versions without leaking memory.  I don't know the application history
well enough to know the best way to proceed, but I see that the 5-second
calling of gethostname() was added in 3.3.2r7 to detect dynamic IP changes.
It's possible that we could cache the hostname once (which hopefully won't
change, even though the IP address may do), but this is assuming that the
gethostbyname() call that resolves the IP doesn't leak at all.  There may of
course be an alternative call to replace gethostname() (maybe a registry
lookup) which will not leak.

Once I've managed to clear enough disk space to install Visual C++ again I
will have a play with this and see what I can come up with.

Any comments on the vailidity of caching the hostname would be appreciated


To unsubscribe, mail majordomo "at" with the line:
'unsubscribe vnc-list' in the message BODY
See also: