Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r66696:906542e248b1
Date: 2013-08-30 11:02 -0700
http://bitbucket.org/pypy/pypy/changeset/906542e248b1/

Log:    fixes for mismatched new/free and malloc/delete as per valgrind

diff --git a/pypy/module/cppyy/src/reflexcwrapper.cxx 
b/pypy/module/cppyy/src/reflexcwrapper.cxx
--- a/pypy/module/cppyy/src/reflexcwrapper.cxx
+++ b/pypy/module/cppyy/src/reflexcwrapper.cxx
@@ -175,7 +175,8 @@
     Reflex::StubFunction stub = (Reflex::StubFunction)method;
     stub(cppresult, (void*)self, arguments, NULL /* stub context */);
     char* cstr = cppstring_to_cstring(*cppresult);
-    delete cppresult;         // the stub will have performed a placement-new
+    cppresult->std::string::~string();
+    free((void*)cppresult);        // the stub will have performed a 
placement-new
     return cstr;
 }
 
@@ -614,11 +615,15 @@
 }
 
 cppyy_object_t cppyy_charp2stdstring(const char* str) {
-    return (cppyy_object_t)new std::string(str);
+    void* arena = new char[sizeof(std::string)];
+    new (arena) std::string(str);
+    return (cppyy_object_t)arena;
 }
 
 cppyy_object_t cppyy_stdstring2stdstring(cppyy_object_t ptr) {
-    return (cppyy_object_t)new std::string(*(std::string*)ptr);
+    void* arena = new char[sizeof(std::string)];
+    new (arena) std::string(*(std::string*)ptr);
+    return (cppyy_object_t)arena;
 }
 
 void cppyy_assign2stdstring(cppyy_object_t ptr, const char* str) {
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to