Message153799
$ mkdir some_directory_ending_with_a.py
$ python -c "import imputil; imputil.imp.find_module('some_directory_ending_with_a')"
*** glibc detected *** python: double free or corruption (!prev): 0x0000000001589bf0 ***
Aborted
What's happening is that call_find_module opens fp, and tries to create a PyFileObject from it:
2844 if (fp != NULL) {
>>2845 fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);
2846 if (fob == NULL) {
2847 fclose(fp);
2848 return NULL;
2849 }
2850 }
The call fails at the very end of fill_file_fields() inside the call to dircheck() here:
180 f->f_fp = fp;
181 f = dircheck(f);
182 return (PyObject *) f;
183 }
184
but f->fp == fp
Hence when fill_file_fields returns NULL, and f is cleaned up here:
484 if (fill_file_fields(f, fp, o_name, mode, close) == NULL) {
>> 485 Py_DECREF(f);
486 Py_DECREF(o_name);
487 return NULL;
488 }
then f->fp is closed within file_dealloc()
Then, when PyFile_FromFile returns NULL, call_find_module calls fclose(fp):
2844 if (fp != NULL) {
2845 fob = PyFile_FromFile(fp, pathname, fdp->mode, fclose);
2846 if (fob == NULL) {
>>2847 fclose(fp);
2848 return NULL;
2849 }
2850 }
and it attempts to close fp for the second time.
The documentation for PyFile_FromFile:
http://docs.python.org/c-api/file.html#PyFile_FromFile
says:
"Return NULL and close the file using close on failure".
It therefore looks like call_find_module's fclose(fp) is incorrect here, and is what leads to the double-free. |
|
Date |
User |
Action |
Args |
2012-02-20 19:01:41 | dmalcolm | set | recipients:
+ dmalcolm |
2012-02-20 19:01:41 | dmalcolm | set | messageid: <1329764501.42.0.487589660736.issue14066@psf.upfronthosting.co.za> |
2012-02-20 19:01:40 | dmalcolm | link | issue14066 messages |
2012-02-20 19:01:40 | dmalcolm | create | |
|