curl-and-python

Re: Crash inside dup()

From: Gisle Vanem <gvanem_at_yahoo.no>
Date: Mon, 23 Dec 2013 21:53:41 +0100

"Oleg Pudeyev" <oleg+pycurl_at_bsdpower.com> wrote:

>> Isn't there a more elegant way to abort things?
>
> This UI is pretty much how abort() has functioned on windows since
> forever.

Your code uses assert(0), which calls abort(). I tried experimenting and
figuring out why my Python 2.7.5 caused a crash in Py_FatalError(). It could
be my Python installation or something.

This change just terminates pycurl.pyd/python.exe with no crash (want I wanted):

    vi->version_num--; // provoke an exit
    if (vi->version_num < LIBCURL_VERSION_NUM) {
        fputs("pycurl: libcurl link-time version is older than compile-time version", stderr);
        Py_Exit(-1);
    }

Without using Py_Exit(), the crash call-stack is as before:

  ntdll!KiFastSystemCallRet
  ntdll!NtTerminateProcess+0xc
  kernel32!_ExitProcess+0x62
  kernel32!ExitProcess+0x14
  MSVCR90!__crtExitProcess+0x17
  MSVCR90!_cinit+0x154
  MSVCR90!_exit+0x11
  MSVCR90!abort+0x116
  WARNING: Stack unwind information not available. Following frames may be wrong.
  python27!Py_FatalError+0x8b
  pycurl!initpycurl(void)+0x24d7 [g:\mingw32\src\inet\curl\pycurl\src\pycurl.c @ 5016]
  python27!PyImportHooks_Init+0x213

From the Py-docs:

void Py_FatalError(const char *message)
  Print a fatal error message and kill the process. No cleanup is performed. This function should
  only be invoked when a condition is detected that would make it dangerous to continue using
  the Python interpreter; e.g., when the object administration appears to be corrupted. On Unix,
  the standard C library function abort() is called which will attempt to produce a core file.

void Py_Exit(int status)
  Exit the current process. This calls Py_Finalize() and then calls the standard C library
  function exit(status).

I think it's important that exit() is called. On Windows at least it seems. Try it and check.
As I've written, I don't know much Python internals. But calling Py_FatalError() seems too
strict in this case. Maybe others too.

And since Py_FatalError() "kill the process", why is an "assert(0)" needed after it?

> Beyond this, what do you think should happen?

Exit the process(es) without crashing.

--gv

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2013-12-23