-- Steve Vavasis
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