segfault/invalid free() in curl_multi.remove_handle()

From: Zdenek Pavlas <>
Date: Wed, 13 Jun 2012 09:12:49 -0400 (EDT)


libcurl does not dispatch signals to Python handlers when waiting
for a reply from a dead server (dtto for a proxy or dns).
I understand implementing this properly is not easy, so tried
to work this around with CurlMulti():

- curl.perform()

+ m = pycurl.CurlMulti()
+ m.add_handle(curl)
+ try:
+ while True:
+ if m.perform()[0] == -1: continue
+ num, ok, err = m.info_read()
+ if ok: break
+ if err: raise pycurl.error(*err[0][1:])
+ if == -1: raise KeyboardInterrupt
+ finally:
+ m.remove_handle(self.curl_obj)

This mostly works, but there are issues when curl blocks in select()
and I hit ctrl-c. m.remove_handle() then sometimes crashes or triggers
this invalid free():

*** glibc detected *** /usr/bin/python: free(): invalid pointer: 0x08c316b0 ***
======= Backtrace: =========

I'm using python-pycurl-7.19.0-7.fc14.i686

I can reproduce this almost consistently, but not in a simple setup.
(it depends eg on how much printing was done, etc)

Is this a bug in curl, or the above Python code is wrong?

Received on 2012-06-13