Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r2779:630f22d1d446
Date: 2016-09-27 11:37 +0200
http://bitbucket.org/cffi/cffi/changeset/630f22d1d446/

Log:    Fix leak. Remaining issue: if the user close()s the file object in
        Python, the __cffi_FILE attribute remains there and the dup'ed file
        descriptor remains open.

diff --git a/c/file_emulator.h b/c/file_emulator.h
--- a/c/file_emulator.h
+++ b/c/file_emulator.h
@@ -31,7 +31,7 @@
 static FILE *PyFile_AsFile(PyObject *ob_file)
 {
     PyObject *ob, *ob_capsule = NULL, *ob_mode = NULL;
-    FILE *f = NULL;
+    FILE *f;
     int fd;
     char *mode;
 
@@ -80,7 +80,11 @@
         if (PyObject_SetAttrString(ob_file, "__cffi_FILE", ob_capsule) < 0)
             goto fail;
     }
-    return PyCapsule_GetPointer(ob_capsule, "FILE");
+    else {
+        f = PyCapsule_GetPointer(ob_capsule, "FILE");
+    }
+    Py_DECREF(ob_capsule);   /* assumes still at least one reference */
+    return f;
 
  fail:
     Py_XDECREF(ob_mode);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to