Probable Pywin32 (win32com.client) bug??

neblackcat neblackcat at
Thu Jul 15 11:46:56 CEST 2004

This is a heads-up on a possible memory corruption type of bug in
recent and present versions of Python/win32com. I dont know if its
general, or specific to using win32com.client to access CDO as my
example does.

My script was tiny - it just opens a MAPI/CDO session and traverses
the email folders - but it keeps crashing Python at random places.

After 2 days of trying everything without success, I've finally
discovered that it depends on how I sequence through a (valid)
collection of folders returned by CDO:

If I do this:

  for o in Folders: something with the 'o' object...

Then the script seems to work OK, but it later crashes Python (in
CDO.DLL according to Windows). If it does crash, its always at the
same (unrelated) place in the script, though this changes "randomly"
whenever the script is changed or run in a different environment (eg.
IDE or command line). This suggests to me that there is some kind of
memory corruption going on.

But if I do this:

      o = Folders.GetFirst()
      while o: something with the 'o' object...
        o = Folders.GetNext()

Then the whole script works (the same) and is totally robust (no
Python crashes).

Could this be some kind of corruption going on within win32com when
the first technique is used? I've googled around, and as far as I can
see this is perfectly valid code.

Is this group the appropriate place to post this, eg. for Mark H to

I have the whole 50-line script available if anyone else wants to try

My system:
XP SP 1a
Outlook 2003 (with its CDO)
Python 2.3.2 (last ActiveState distribution) or 2.3.4 
Pywin32 2.02 for Python 2.3

More information about the Python-list mailing list