[Lldb-commits] [PATCH] D18459: Fix FILE * leak in Python API

Francis Ricci via lldb-commits lldb-commits at lists.llvm.org
Fri Mar 25 16:32:29 PDT 2016


fjricci updated this revision to Diff 51699.
fjricci added a comment.

Fix whitespace


http://reviews.llvm.org/D18459

Files:
  include/lldb/API/SBCommandReturnObject.h
  scripts/interface/SBCommandReturnObject.i
  source/API/SBCommandReturnObject.cpp

Index: source/API/SBCommandReturnObject.cpp
===================================================================
--- source/API/SBCommandReturnObject.cpp
+++ source/API/SBCommandReturnObject.cpp
@@ -258,15 +258,27 @@
 void
 SBCommandReturnObject::SetImmediateOutputFile(FILE *fh)
 {
-    if (m_opaque_ap)
-        m_opaque_ap->SetImmediateOutputFile(fh);
+    SetImmediateOutputFile(fh, false);
 }
 
 void
 SBCommandReturnObject::SetImmediateErrorFile(FILE *fh)
 {
+    SetImmediateErrorFile(fh, false);
+}
+
+void
+SBCommandReturnObject::SetImmediateOutputFile(FILE *fh, bool transfer_ownership)
+{
+    if (m_opaque_ap)
+        m_opaque_ap->SetImmediateOutputFile(fh, transfer_ownership);
+}
+
+void
+SBCommandReturnObject::SetImmediateErrorFile(FILE *fh, bool transfer_ownership)
+{
     if (m_opaque_ap)
-        m_opaque_ap->SetImmediateErrorFile(fh);
+        m_opaque_ap->SetImmediateErrorFile(fh, transfer_ownership);
 }
 
 void
Index: scripts/interface/SBCommandReturnObject.i
===================================================================
--- scripts/interface/SBCommandReturnObject.i
+++ scripts/interface/SBCommandReturnObject.i
@@ -84,11 +84,17 @@
     bool
     GetDescription (lldb::SBStream &description);
     
-    void
-    SetImmediateOutputFile (FILE *fh);
-    
-    void
-    SetImmediateErrorFile (FILE *fh);
+
+    // wrapping here so that lldb takes ownership of the 
+    // new FILE* created inside of the swig interface
+    %extend {
+        void SetImmediateOutputFile(FILE *fh) {
+            self->SetImmediateOutputFile(fh, true);
+        }
+        void SetImmediateErrorFile(FILE *fh) {
+            self->SetImmediateErrorFile(fh, true);
+        }
+    }
 
 	void
 	PutCString(const char* string, int len);
Index: include/lldb/API/SBCommandReturnObject.h
===================================================================
--- include/lldb/API/SBCommandReturnObject.h
+++ include/lldb/API/SBCommandReturnObject.h
@@ -83,14 +83,22 @@
     
     bool
     GetDescription (lldb::SBStream &description);
-    
+   
+    // deprecated, these two functions do not take
+    // ownership of file handle
     void
     SetImmediateOutputFile (FILE *fh);
     
     void
     SetImmediateErrorFile (FILE *fh);
     
     void
+    SetImmediateOutputFile (FILE *fh, bool transfer_ownership);
+    
+    void
+    SetImmediateErrorFile (FILE *fh, bool transfer_ownership);
+    
+    void
     PutCString(const char* string, int len = -1);
     
     size_t


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18459.51699.patch
Type: text/x-patch
Size: 2492 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160325/2b444705/attachment-0001.bin>


More information about the lldb-commits mailing list