Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

bug in "DisplayCanvas"

12 views
Skip to first unread message

Stephen Vavasis

unread,
Aug 9, 1998, 3:00:00 AM8/9/98
to
This message pertains to Tcl/Tk 8.0 running under Windows NT and
compiled with MSVC++5.0. The procedure "DisplayCanvas" in tkCanvas.c
initializes a variable "pixmap" with the return value from Tk_GetPixmap,
which in turn calls CreateBitmap, a Win32 procedure. According to the
MSVC documentation, the CreateBitmap procedure can return a NULL (and
indeed, it did in my case. I don't know why it returned a null -- the
problem disappeared after I rebooted my machine). Tk_GetPixmap checks
for the NULL, and if it is caught, frees memory and passes a NULL back
to its caller. But DisplayCanvas uses pixmap without checking whether
NULL has been returned by Tk_GetPixmap. So eventually an access
violation occurs.

-- Steve Vavasis

George A. Howlett

unread,
Aug 11, 1998, 3:00:00 AM8/11/98
to
Stephen Vavasis (vav...@cs.cornell.edu) wrote:
: This message pertains to Tcl/Tk 8.0 running under Windows NT and

Tk for Windows, uses an Xlib emulation layer that makes Win32 calls.
The Win32 and X11 APIs have different styles.

Under X11, if a resource can't be allocated, the X server generates an
error and calls a default error handler which eventually terminates
your program. This means that you don't have to constantly check the
return values of all the different Xlib functions. Most of the time
the Xlib calls don't fail. But on the other hand, you'll need to
install an error handler to catch the error if you don't want your
program to terminate.

Win32 simply returns a NULL handle when a resource can't be allocated.
Here one should check the return values for things like CreateBitmap.

But since Tk doesn't also emulate the X server's error mechanism, it
does some weak checking. You'll notice that most the Xlib emulation
routines check for a NULL drawable.

It's a nasty problem because resource leaks can make other Win32
functions to fail. If you have a widget (in Tk or another extension)
that fails to release the GDI objects it allocates, sooner or later a
call to allocate a resource will fail. Now it doesn't have to be just
bitmaps (via Tk_GetPixmap), there are pens and brushes too. It just
seems to show up there because pixmaps are used extensively for
redraws (double buffering).

So while it looks like Tk_GetPixmap is the problem, it's actually a
resource leak somewhere else. The best thing you can do is to try to
generate a simple test script that demonstrates the problem. Then
using a tool like BoundChecker or Purify (or a checked build) you (or
someone else) can see where the leak is occuring.

--gah

0 new messages