fjricci created this revision.
fjricci added reviewers: clayborg, granata.enrico, zturner.
fjricci added subscribers: sas, lldb-commits.

This reverts some of the changes made by:
r257644
r250530
r250525

The changes made in these patches result in leaking the FILE* passed
to SetImmediateOutputFile. GetStream() will dup() the fd held by the
python caller and create a new FILE*. It will then pass this FILE*
to SetImmediateOutputFile, which always uses the flag
transfer_ownership=false when it creates a File from the FILE*.

Since transfer_ownership is false, the lldb File destructor will not
close the underlying FILE*. Because this FILE* came from a dup-ed fd,
it will also not be closed when the python caller closes its file.

Leaking the FILE* causes issues if the same file is used multiple times
by different python callers during the same lldb run, even if these
callers open and close the python file properly, as you can end up
with issues due to multiple buffered writes to the same file.

http://reviews.llvm.org/D18459

Files:
  scripts/Python/python-typemaps.swig

Index: scripts/Python/python-typemaps.swig
===================================================================
--- scripts/Python/python-typemaps.swig
+++ scripts/Python/python-typemaps.swig
@@ -520,16 +520,7 @@
       }
    }
    else
-   {
-      PythonFile py_file(PyRefType::Borrowed, $input);
-      File file;
-      if (!py_file.GetUnderlyingFile(file))
-         return nullptr;
-
-      $1 = file.GetStream();
-      if ($1)
-         file.Clear();
-    }
+     $1 = PyFile_AsFile($input);
 }
 
 %typemap(out) FILE * {


Index: scripts/Python/python-typemaps.swig
===================================================================
--- scripts/Python/python-typemaps.swig
+++ scripts/Python/python-typemaps.swig
@@ -520,16 +520,7 @@
       }
    }
    else
-   {
-      PythonFile py_file(PyRefType::Borrowed, $input);
-      File file;
-      if (!py_file.GetUnderlyingFile(file))
-         return nullptr;
-
-      $1 = file.GetStream();
-      if ($1)
-         file.Clear();
-    }
+     $1 = PyFile_AsFile($input);
 }
 
 %typemap(out) FILE * {
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to