You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2011/01/09 04:39:09 UTC

svn commit: r1056880 - in /tuscany/sca-cpp/trunk: components/cache/ components/chat/ components/filedb/ components/log/ components/nosqldb/ components/queue/ components/sqldb/ components/webservice/ etc/ kernel/ modules/http/ modules/java/ modules/js/ ...

Author: jsdelfino
Date: Sun Jan  9 03:39:08 2011
New Revision: 1056880

URL: http://svn.apache.org/viewvc?rev=1056880&view=rev
Log:
Fix memory leak in Python runtime integration. Reduce memory consumption of debug trace functions. Add trace points to help track the lifecycle of some of the runtime context objects.

Added:
    tuscany/sca-cpp/trunk/modules/http/httpd-debug
      - copied, changed from r1056190, tuscany/sca-cpp/trunk/modules/http/httpd-stop
    tuscany/sca-cpp/trunk/modules/http/httpd-memgrind
      - copied, changed from r1056190, tuscany/sca-cpp/trunk/modules/http/httpd-stop
Modified:
    tuscany/sca-cpp/trunk/components/cache/memcache.hpp
    tuscany/sca-cpp/trunk/components/chat/xmpp.hpp
    tuscany/sca-cpp/trunk/components/filedb/filedb.hpp
    tuscany/sca-cpp/trunk/components/log/scribe.hpp
    tuscany/sca-cpp/trunk/components/nosqldb/tinycdb.hpp
    tuscany/sca-cpp/trunk/components/queue/qpid.hpp
    tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp
    tuscany/sca-cpp/trunk/components/webservice/axis2.hpp
    tuscany/sca-cpp/trunk/etc/memgrind
    tuscany/sca-cpp/trunk/kernel/config.hpp
    tuscany/sca-cpp/trunk/kernel/fstream.hpp
    tuscany/sca-cpp/trunk/modules/http/httpd-stop
    tuscany/sca-cpp/trunk/modules/http/httpd.hpp
    tuscany/sca-cpp/trunk/modules/http/mod-openauth.cpp
    tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
    tuscany/sca-cpp/trunk/modules/java/eval.hpp
    tuscany/sca-cpp/trunk/modules/js/eval.hpp
    tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
    tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
    tuscany/sca-cpp/trunk/modules/python/eval.hpp
    tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
    tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp

Modified: tuscany/sca-cpp/trunk/components/cache/memcache.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/memcache.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/memcache.hpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/memcache.hpp Sun Jan  9 03:39:08 2011
@@ -49,24 +49,30 @@ namespace memcache {
 class MemCached {
 public:
     MemCached() : owner(false) {
+        debug("memcache::memcached");
     }
 
     MemCached(const string host, const int port) : owner(true) {
+        debug(host, "memcache::memcached::host");
+        debug(port, "memcache::memcached::port");
         apr_pool_create(&pool, NULL);
         apr_memcache_create(pool, 1, 0, &mc);
         addServer(host, port);
     }
 
     MemCached(const list<string>& servers) : owner(true) {
+        debug(servers, "memcache::memcached::servers");
         apr_pool_create(&pool, NULL);
         apr_memcache_create(pool, 1, 0, &mc);
         addServers(servers);
     }
 
     MemCached(const MemCached& c) : owner(false), pool(c.pool), mc(c.mc) {
+        debug("memcache::memcached::copy");
     }
 
     ~MemCached() {
+        debug("memcache::~memcached");
         if (!owner)
             return;
         apr_pool_destroy(pool);

Modified: tuscany/sca-cpp/trunk/components/chat/xmpp.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/chat/xmpp.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/chat/xmpp.hpp (original)
+++ tuscany/sca-cpp/trunk/components/chat/xmpp.hpp Sun Jan  9 03:39:08 2011
@@ -45,11 +45,13 @@ namespace chat {
 class XMPPRuntime {
 public:
     XMPPRuntime() {
+        debug("chat::xmppruntime");
         xmpp_initialize();
         log = xmpp_get_default_logger(XMPP_LEVEL_DEBUG);
     }
 
     ~XMPPRuntime() {
+        debug("chat::~xmppruntime");
         xmpp_shutdown();
     }
 
@@ -67,12 +69,15 @@ public:
     XMPPClient(const string& jid, const string& pass, bool owner = true) : owner(owner), ctx(xmpp_ctx_new(NULL, xmppRuntime.log)), conn(xmpp_conn_new(ctx)), connecting(false), connected(false), disconnecting(false) {
         xmpp_conn_set_jid(conn, c_str(jid + "/" + mkuuid()));
         xmpp_conn_set_pass(conn, c_str(pass));
+        debug(jid, "chat::xmppclient::jid");
     }
 
     XMPPClient(const XMPPClient& xc) : owner(false), ctx(xc.ctx), conn(xc.conn), listener(xc.listener),  connecting(xc.connecting), connected(xc.connected), disconnecting(xc.disconnecting) {
+        debug("chat::xmppclient::copy");
     }
 
     ~XMPPClient() {
+        debug("chat::~xmppclient");
         extern const failable<bool> disconnect(XMPPClient& xc);
         if (!owner)
             return;

Modified: tuscany/sca-cpp/trunk/components/filedb/filedb.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/filedb/filedb.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/filedb/filedb.hpp (original)
+++ tuscany/sca-cpp/trunk/components/filedb/filedb.hpp Sun Jan  9 03:39:08 2011
@@ -45,15 +45,20 @@ namespace filedb {
 class FileDB {
 public:
     FileDB() : owner(false), jscx(*jscontext("")) {
+        debug("filedb::filedb");
     }
 
     FileDB(const string& name, const string& format) : owner(true), name(name), format(format), jscx(*jscontext(format)) {
+        debug(name, "filedb::filedb::name");
+        debug(format, "filedb::filedb::format");
     }
 
     FileDB(const FileDB& c) : owner(false), name(c.name), format(c.format), jscx(c.jscx) {
+        debug("filedb::filedb::copy");
     }
 
     ~FileDB() {
+        debug("filedb::~filedb");
     }
 
 private:

Modified: tuscany/sca-cpp/trunk/components/log/scribe.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/log/scribe.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/log/scribe.hpp (original)
+++ tuscany/sca-cpp/trunk/components/log/scribe.hpp Sun Jan  9 03:39:08 2011
@@ -65,18 +65,23 @@ namespace scribe {
 class Scribe {
 public:
     Scribe() : owner(false) {
+        debug("scribe::scribe");
     }
 
     Scribe(const string host, const int port) : owner(true) {
+        debug(host, "scribe::scribe::host");
+        debug(port, "scribe::scribe::port");
         init(host, port);
     }
 
     Scribe(const Scribe& c) : owner(false) {
+        debug("scribe::scribe::copy");
         client = c.client;
         transport = c.transport;
     }
 
     ~Scribe() {
+        debug("scribe::~scribe");
         if (!owner)
             return;
         try {

Modified: tuscany/sca-cpp/trunk/components/nosqldb/tinycdb.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/nosqldb/tinycdb.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/nosqldb/tinycdb.hpp (original)
+++ tuscany/sca-cpp/trunk/components/nosqldb/tinycdb.hpp Sun Jan  9 03:39:08 2011
@@ -95,18 +95,22 @@ const bool free(const buffer&b) {
 class TinyCDB {
 public:
     TinyCDB() : owner(false), fd(-1) {
+        debug("tinycdb::tinycdb");
         st.st_ino = 0;
     }
 
     TinyCDB(const string& name) : owner(true), name(name), fd(-1) {
+        debug(name, "tinycdb::tinycdb::name");
         st.st_ino = 0;
     }
 
     TinyCDB(const TinyCDB& c) : owner(false), name(c.name), fd(c.fd) {
+        debug("tinycdb::tinycdb::copy");
         st.st_ino = c.st.st_ino;
     }
 
     ~TinyCDB() {
+        debug("tinycdb::~tinycdb");
         if (!owner)
             return;
         if (fd == -1)

Modified: tuscany/sca-cpp/trunk/components/queue/qpid.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/queue/qpid.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/queue/qpid.hpp (original)
+++ tuscany/sca-cpp/trunk/components/queue/qpid.hpp Sun Jan  9 03:39:08 2011
@@ -52,17 +52,21 @@ namespace queue {
 class QpidConnection {
 public:
     QpidConnection() : owner(true) {
+        debug("queue::qpidonnection");
         c.open("localhost", 5672);
     }
 
     QpidConnection(const bool owner) : owner(owner) {
+        debug("queue::qpidonnection");
         c.open("localhost", 5672);
     }
 
     QpidConnection(const QpidConnection& qc) : owner(false), c(qc.c) {
+        debug("queue::qpidonnection::copy");
     }
 
     ~QpidConnection() {
+        debug("queue::~qpidonnection");
         if (!owner)
             return;
         c.close();
@@ -91,15 +95,19 @@ const failable<bool> close(QpidConnectio
 class QpidSession {
 public:
     QpidSession(QpidConnection& qc) : owner(true), s(qc.c.newSession()) {
+        debug("queue::qpidsession");
     }
 
     QpidSession(QpidConnection& qc, const bool owner) : owner(owner), s(qc.c.newSession()) {
+        debug("queue::qpidsession");
     }
 
     QpidSession(const QpidSession& qs) : owner(false), s(qs.s) {
+        debug("queue::qpidsession::copy");
     }
 
     ~QpidSession() {
+        debug("queue::~qpidsession");
         if (!owner)
             return;
         s.close();

Modified: tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp (original)
+++ tuscany/sca-cpp/trunk/components/sqldb/pgsql.hpp Sun Jan  9 03:39:08 2011
@@ -55,9 +55,12 @@ const string pgfailure(PGresult* r, PGco
 class PGSql {
 public:
     PGSql() : owner(false) {
+        debug("pgsql::pgsql");
     }
 
     PGSql(const string& conninfo, const string& table) : owner(true), conn(NULL), conninfo(conninfo), table(table) {
+        debug(conninfo, "pgsql::pgsql::conninfo");
+        debug(table, "pgsql::pgsql::table");
         conn = PQconnectdb(c_str(conninfo));
         if (PQstatus(conn) != CONNECTION_OK) {
             mkfailure<bool>(string("Could not connect to postgresql database: ") + PQerrorMessage(conn));
@@ -67,9 +70,11 @@ public:
     }
 
     PGSql(const PGSql& c) : owner(false), conn(c.conn), conninfo(c.conninfo), table(c.table) {
+        debug("pgsql::pgsql::copy");
     }
 
     ~PGSql() {
+        debug("pgsql::~pgsql");
         if (!owner)
             return;
         if (conn == NULL)

Modified: tuscany/sca-cpp/trunk/components/webservice/axis2.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/webservice/axis2.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/webservice/axis2.hpp (original)
+++ tuscany/sca-cpp/trunk/components/webservice/axis2.hpp Sun Jan  9 03:39:08 2011
@@ -58,15 +58,19 @@ namespace webservice {
 class Axis2Context {
 public:
     Axis2Context() : env(axutil_env_create_all("axis2.log", AXIS2_LOG_LEVEL_WARNING)), owner(true) {
+        debug("webservice::axis2context");
     }
 
     Axis2Context(const Axis2Context& ax) : env(ax.env), owner(false) {
+        debug("webservice::axis2context::copy");
     }
 
     Axis2Context(const axutil_env_t* env) : env(const_cast<axutil_env_t*>(env)), owner(false) {
+        debug("webservice::axis2context::env");
     }
 
     ~Axis2Context() {
+        debug("webservice::~axis2context");
         if (!owner || env == NULL)
             return;
         axutil_env_free(env);

Modified: tuscany/sca-cpp/trunk/etc/memgrind
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/etc/memgrind?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/etc/memgrind (original)
+++ tuscany/sca-cpp/trunk/etc/memgrind Sun Jan  9 03:39:08 2011
@@ -19,5 +19,5 @@
 
 # Run valgrind to analyze memory usage and track memory leaks
 
-valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=20 --track-fds=yes $* 2>&1 | tee memgrind.log
+valgrind --tool=memcheck --leak-check=yes --show-reachable=yes --num-callers=40 --track-fds=yes $* 2>&1 | tee memgrind.log
 

Modified: tuscany/sca-cpp/trunk/kernel/config.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/config.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/config.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/config.hpp Sun Jan  9 03:39:08 2011
@@ -43,7 +43,7 @@ namespace tuscany
 /**
  * Add string watch members to important classes to help watch them in a debugger.
  */
-#define WANT_MAINTAINER_WATCH
+//#define WANT_MAINTAINER_WATCH
 
 /**
  * Increment / decrement a debug counter.

Modified: tuscany/sca-cpp/trunk/kernel/fstream.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/kernel/fstream.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/kernel/fstream.hpp (original)
+++ tuscany/sca-cpp/trunk/kernel/fstream.hpp Sun Jan  9 03:39:08 2011
@@ -229,6 +229,7 @@ logfstream cdebug(stderr, "debug");
  * Log a debug message.
  */
 const bool debugLog(const string& msg) {
+    gc_scoped_pool();
     cdebug << msg << endl;
     return true;
 }
@@ -237,6 +238,7 @@ const bool debugLog(const string& msg) {
  * Log a debug message and a value.
  */
 template<typename V> const bool debugLog(const V& v, const string& msg) {
+    gc_scoped_pool();
     cdebug << msg << ": " << v << endl;
     return true;
 }

Copied: tuscany/sca-cpp/trunk/modules/http/httpd-debug (from r1056190, tuscany/sca-cpp/trunk/modules/http/httpd-stop)
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd-debug?p2=tuscany/sca-cpp/trunk/modules/http/httpd-debug&p1=tuscany/sca-cpp/trunk/modules/http/httpd-stop&r1=1056190&r2=1056880&rev=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd-stop (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd-debug Sun Jan  9 03:39:08 2011
@@ -17,9 +17,9 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# Stop httpd server
+# Start httpd server
 here=`readlink -f $0`; here=`dirname $here`
 root=`readlink -f $1`
 
-apachectl=`cat $here/httpd-apachectl.prefix`
-$apachectl -k graceful-stop -d $root -f $root/conf/httpd.conf
+httpd=`cat $here/httpd.prefix`
+$httpd/bin/httpd -X -E $root/logs/error_log -d $root -f $root/conf/httpd.conf

Copied: tuscany/sca-cpp/trunk/modules/http/httpd-memgrind (from r1056190, tuscany/sca-cpp/trunk/modules/http/httpd-stop)
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd-memgrind?p2=tuscany/sca-cpp/trunk/modules/http/httpd-memgrind&p1=tuscany/sca-cpp/trunk/modules/http/httpd-stop&r1=1056190&r2=1056880&rev=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd-stop (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd-memgrind Sun Jan  9 03:39:08 2011
@@ -17,9 +17,9 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# Stop httpd server
+# Start httpd server
 here=`readlink -f $0`; here=`dirname $here`
 root=`readlink -f $1`
 
-apachectl=`cat $here/httpd-apachectl.prefix`
-$apachectl -k graceful-stop -d $root -f $root/conf/httpd.conf
+httpd=`cat $here/httpd.prefix`
+$here/../../etc/memgrind $httpd/bin/httpd -X -E $root/logs/error_log -d $root -f $root/conf/httpd.conf

Modified: tuscany/sca-cpp/trunk/modules/http/httpd-stop
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd-stop?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd-stop (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd-stop Sun Jan  9 03:39:08 2011
@@ -22,4 +22,4 @@ here=`readlink -f $0`; here=`dirname $he
 root=`readlink -f $1`
 
 apachectl=`cat $here/httpd-apachectl.prefix`
-$apachectl -k graceful-stop -d $root -f $root/conf/httpd.conf
+$apachectl -k graceful-stop -d $root -f $root/conf/httpd.conf 2>/dev/null

Modified: tuscany/sca-cpp/trunk/modules/http/httpd.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/httpd.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/httpd.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/httpd.hpp Sun Jan  9 03:39:08 2011
@@ -631,6 +631,7 @@ const char* debugOptional(const char* s)
  * Log a header
  */
 int debugHeader(unused void* r, const char* key, const char* value) {
+    gc_scoped_pool();
     cdebug << "  header key: " << key << ", value: " << value << endl;
     return 1;
 }
@@ -639,6 +640,7 @@ int debugHeader(unused void* r, const ch
  * Log an environment variable
  */
 int debugEnv(unused void* r, const char* key, const char* value) {
+    gc_scoped_pool();
     cdebug << "  var key: " << key << ", value: " << value << endl;
     return 1;
 }
@@ -647,6 +649,7 @@ int debugEnv(unused void* r, const char*
  * Log a note.
  */
 int debugNote(unused void* r, const char* key, const char* value) {
+    gc_scoped_pool();
     cdebug << "  note key: " << key << ", value: " << value << endl;
     return 1;
 }
@@ -655,6 +658,7 @@ int debugNote(unused void* r, const char
  * Log a request.
  */
 const bool debugRequest(request_rec* r, const string& msg) {
+    gc_scoped_pool();
     cdebug << msg << ":" << endl;
     cdebug << "  unparsed uri: " << debugOptional(r->unparsed_uri) << endl;
     cdebug << "  uri: " << debugOptional(r->uri) << endl;

Modified: tuscany/sca-cpp/trunk/modules/http/mod-openauth.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/mod-openauth.cpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/mod-openauth.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/mod-openauth.cpp Sun Jan  9 03:39:08 2011
@@ -202,6 +202,7 @@ static int checkAuthn(request_rec *r) {
     if (atype == NULL || strcasecmp(atype, "Open"))
         return DECLINED;
 
+    // Create a scoped memory pool
     gc_scoped_pool pool(r->pool);
     httpdDebugRequest(r, "modopenauth::checkAuthn::input");
 

Modified: tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp Sun Jan  9 03:39:08 2011
@@ -264,7 +264,9 @@ int processConnection(conn_rec *conn) {
     if (ap_get_module_config(conn->base_server->module_config, &mod_tuscany_ssltunnel) == NULL)
         return DECLINED;
 
-    gc_scoped_pool(conn->pool);
+    // Create a scoped memory pool
+    gc_scoped_pool pool;
+
     const ServerConf& sc = httpd::serverConf<ServerConf>(conn->base_server, &mod_tuscany_ssltunnel);
     if (length(sc.pass) == 0)
         return DECLINED;
@@ -287,6 +289,9 @@ int handler(request_rec* r) {
     if (strcmp(r->server->server_scheme, "https"))
         return DECLINED;
 
+    // Create a scoped memory pool
+    gc_scoped_pool pool(r->pool);
+
     // Build the target URL
     debug(r->uri, "modssltunnel::handler::uri");
     const list<value> path(pathValues(r->uri));

Modified: tuscany/sca-cpp/trunk/modules/java/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/java/eval.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/java/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/java/eval.hpp Sun Jan  9 03:39:08 2011
@@ -51,6 +51,7 @@ jobject JNICALL nativeUUID(JNIEnv *env);
 class JavaRuntime {
 public:
     JavaRuntime() {
+        debug("java::javaruntime");
 
         // Get existing JVM
         jsize nvms = 0;
@@ -151,6 +152,10 @@ public:
         env->RegisterNatives(uuidClass, &uuidnm, 1);
     }
 
+    ~JavaRuntime() {
+        debug("java::~javaruntime");
+    }
+
     JavaVM* jvm;
     JNIEnv* env;
 

Modified: tuscany/sca-cpp/trunk/modules/js/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/js/eval.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/js/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/js/eval.hpp Sun Jan  9 03:39:08 2011
@@ -55,6 +55,7 @@ class JSRuntime {
 public:
     JSRuntime() {
         // Create JS runtime
+        debug("js::jsruntime");
         rt = JS_NewRuntime(8L * 1024L * 1024L);
         if(rt == NULL)
             cleanup();
@@ -63,6 +64,11 @@ public:
     operator ::JSRuntime*() const {
         return rt;
     }
+
+    ~JSRuntime() {
+        debug("js::~jsruntime");
+    }
+
 private:
     bool cleanup() {
         if(rt != NULL) {
@@ -86,6 +92,7 @@ class JSContext {
 public:
     JSContext() {
         // Create JS context
+        debug("js::jscontext");
         cx = JS_NewContext(jsRuntime, 8192);
         if(cx == NULL)
             return;
@@ -108,6 +115,7 @@ public:
     }
 
     ~JSContext() {
+        debug("js::~jscontext");
         cleanup();
     }
 

Modified: tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp Sun Jan  9 03:39:08 2011
@@ -394,7 +394,10 @@ static int checkAuthn(request_rec *r) {
     if (atype == NULL || strcasecmp(atype, "Open"))
         return DECLINED;
 
+    // Create a scoped memory pool
     gc_scoped_pool pool(r->pool);
+
+    // Get the server configuration
     httpdDebugRequest(r, "modoauth1::checkAuthn::input");
     const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_oauth1);
 

Modified: tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp Sun Jan  9 03:39:08 2011
@@ -246,7 +246,10 @@ static int checkAuthn(request_rec *r) {
     if (atype == NULL || strcasecmp(atype, "Open"))
         return DECLINED;
 
+    // Create a scoped memory pool
     gc_scoped_pool pool(r->pool);
+
+    // Get the server configuration
     httpdDebugRequest(r, "modoauth2::checkAuthn::input");
     const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_oauth2);
 

Modified: tuscany/sca-cpp/trunk/modules/python/eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/python/eval.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/python/eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/python/eval.hpp Sun Jan  9 03:39:08 2011
@@ -39,12 +39,17 @@ namespace python {
 class PythonRuntime {
 public:
     PythonRuntime() {
+        debug("python::pythonruntime");
         if (Py_IsInitialized())
             return;
         Py_InitializeEx(0);
         const char* arg0 = "";
         PySys_SetArgv(0, const_cast<char**>(&arg0));
     }
+
+    ~PythonRuntime() {
+        debug("python::~pythonruntime");
+    }
 };
 
 /**
@@ -97,11 +102,15 @@ typedef struct {
 PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l);
 
 void pyLambda_dealloc(PyObject* self) {
-    PyMem_DEL(self);
+    debug(self, "python::pylambda_dealloc");
+    PyObject_Del(self);
 }
 
-const string pyRepr(PyObject * o) {
-    return PyString_AsString(PyObject_Repr(o));
+const string pyRepr(PyObject* o) {
+    PyObject* r = PyObject_Repr(o);
+    const string s = PyString_AsString(r);
+    Py_DECREF(r);
+    return s;
 }
 
 PyObject* pyLambda_call(PyObject* self, PyObject* args, unused PyObject* kwds) {
@@ -109,9 +118,7 @@ PyObject* pyLambda_call(PyObject* self, 
     const pyLambda* pyl = (pyLambda*)self;
     const value result = pyl->func(pyTupleToValues(args));
     debug(result, "python::call::result");
-    Py_DECREF(args);
     PyObject *pyr = valueToPyObject(result);
-    Py_INCREF(pyr);
     return pyr;
 }
 
@@ -143,7 +150,6 @@ PyObject* pyLambda_getattr(PyObject *sel
     const pyLambda* pyl = (pyLambda*)self;
     debug(name, "python::getattr::name");
     PyObject* pyr = mkPyLambda(pyProxy(name, pyl->func));
-    Py_INCREF(pyr);
     return pyr;
 }
 
@@ -169,9 +175,10 @@ PyTypeObject pyLambda_type = {
  */
 PyObject *mkPyLambda(const lambda<value(const list<value>&)>& l) {
     pyLambda* pyl = NULL;
-    pyl = PyObject_NEW(pyLambda, &pyLambda_type);
+    pyl = PyObject_New(pyLambda, &pyLambda_type);
     if (pyl != NULL)
       pyl->func = l;
+    debug(pyl, "python::mkpylambda");
     return (PyObject *)pyl;
 }
 
@@ -181,12 +188,17 @@ PyObject *mkPyLambda(const lambda<value(
 PyObject* valuesToPyListHelper(PyObject* l, const list<value>& v) {
     if (isNil(v))
         return l;
-    PyList_Append(l, valueToPyObject(car(v)));
+    PyObject* pyv = valueToPyObject(car(v));
+    PyList_Append(l, pyv);
+    Py_DECREF(pyv);
     return valuesToPyListHelper(l, cdr(v));
 }
 
 PyObject* valuesToPyTuple(const list<value>& v) {
-    return PyList_AsTuple(valuesToPyListHelper(PyList_New(0), v));
+    PyObject* pyl = valuesToPyListHelper(PyList_New(0), v);
+    PyObject* pyt = PyList_AsTuple(pyl);
+    Py_DECREF(pyl);
+    return pyt;
 }
 
 /**
@@ -242,8 +254,8 @@ struct pyCallable {
     const value operator()(const list<value>& args) const {
         PyObject* pyargs = valuesToPyTuple(args);
         PyObject* result = PyObject_CallObject(func, pyargs);
-        Py_DECREF(pyargs);
         const value v = pyObjectToValue(result);
+        Py_DECREF(pyargs);
         Py_DECREF(result);
         return v;
     }
@@ -309,8 +321,8 @@ const failable<value> evalScript(const v
 
     // Call the function
     PyObject* result = PyObject_CallObject(func, args);
-    Py_DECREF(args);
     Py_DECREF(func);
+    Py_DECREF(args);
     if (result == NULL)
         return mkfailure<value>(string("Function call failed: ") + car<value>(expr) + " : " + lastError());
 

Modified: tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-eval.hpp Sun Jan  9 03:39:08 2011
@@ -628,7 +628,9 @@ int handler(request_rec *r) {
     if(strcmp(r->handler, "mod_tuscany_eval"))
         return DECLINED;
 
+    // Create a scoped memory pool
     gc_scoped_pool pool(r->pool);
+
     ScopedRequest sr(r);
     httpdDebugRequest(r, "modeval::handler::input");
 

Modified: tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp?rev=1056880&r1=1056879&r2=1056880&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp (original)
+++ tuscany/sca-cpp/trunk/modules/server/mod-wiring.cpp Sun Jan  9 03:39:08 2011
@@ -310,8 +310,10 @@ int translate(request_rec *r) {
     if (!strncmp(r->uri, "/components/", 12))
         return DECLINED;
 
-    // Get the server configuration
+    // Create a scoped memory pool
     gc_scoped_pool pool(r->pool);
+
+    // Get the server configuration
     const ServerConf& sc = httpd::serverConf<ServerConf>(r, &mod_tuscany_wiring);
 
     // Process dynamic virtual host configuration
@@ -346,8 +348,10 @@ int handler(request_rec *r) {
     if (r->status == HTTP_MOVED_TEMPORARILY)
         return OK;
 
-    // Do an internal redirect
+    // Create a scoped memory pool
     gc_scoped_pool pool(r->pool);
+
+    // Do an internal redirect
     httpdDebugRequest(r, "modwiring::handler::input");
 
     debug(r->uri, "modwiring::handler::uri");