summaryrefslogtreecommitdiffstats
path: root/sca-cpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-01-09 03:39:08 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2011-01-09 03:39:08 +0000
commit2e9c610931b4e0a6bab25b1fe5dbd0def45ee126 (patch)
tree1c740e32afcfc6570b5e87d179c12854ea4f686c /sca-cpp
parentd2a4018d6c354a75e45800f90f45d09469bc4db5 (diff)
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.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1056880 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp')
-rw-r--r--sca-cpp/trunk/components/cache/memcache.hpp6
-rw-r--r--sca-cpp/trunk/components/chat/xmpp.hpp5
-rw-r--r--sca-cpp/trunk/components/filedb/filedb.hpp5
-rw-r--r--sca-cpp/trunk/components/log/scribe.hpp5
-rw-r--r--sca-cpp/trunk/components/nosqldb/tinycdb.hpp4
-rw-r--r--sca-cpp/trunk/components/queue/qpid.hpp8
-rw-r--r--sca-cpp/trunk/components/sqldb/pgsql.hpp5
-rw-r--r--sca-cpp/trunk/components/webservice/axis2.hpp4
-rwxr-xr-xsca-cpp/trunk/etc/memgrind2
-rw-r--r--sca-cpp/trunk/kernel/config.hpp2
-rw-r--r--sca-cpp/trunk/kernel/fstream.hpp2
-rwxr-xr-xsca-cpp/trunk/modules/http/httpd-debug25
-rwxr-xr-xsca-cpp/trunk/modules/http/httpd-memgrind25
-rwxr-xr-xsca-cpp/trunk/modules/http/httpd-stop2
-rw-r--r--sca-cpp/trunk/modules/http/httpd.hpp4
-rw-r--r--sca-cpp/trunk/modules/http/mod-openauth.cpp1
-rw-r--r--sca-cpp/trunk/modules/http/mod-ssltunnel.cpp7
-rw-r--r--sca-cpp/trunk/modules/java/eval.hpp5
-rw-r--r--sca-cpp/trunk/modules/js/eval.hpp8
-rw-r--r--sca-cpp/trunk/modules/oauth/mod-oauth1.cpp3
-rw-r--r--sca-cpp/trunk/modules/oauth/mod-oauth2.cpp3
-rw-r--r--sca-cpp/trunk/modules/python/eval.hpp34
-rw-r--r--sca-cpp/trunk/modules/server/mod-eval.hpp2
-rw-r--r--sca-cpp/trunk/modules/server/mod-wiring.cpp8
24 files changed, 158 insertions, 17 deletions
diff --git a/sca-cpp/trunk/components/cache/memcache.hpp b/sca-cpp/trunk/components/cache/memcache.hpp
index a76af6b662..e4cdceb6fa 100644
--- a/sca-cpp/trunk/components/cache/memcache.hpp
+++ b/sca-cpp/trunk/components/cache/memcache.hpp
@@ -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);
diff --git a/sca-cpp/trunk/components/chat/xmpp.hpp b/sca-cpp/trunk/components/chat/xmpp.hpp
index 3a6aa86c5c..cafe342f05 100644
--- a/sca-cpp/trunk/components/chat/xmpp.hpp
+++ b/sca-cpp/trunk/components/chat/xmpp.hpp
@@ -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;
diff --git a/sca-cpp/trunk/components/filedb/filedb.hpp b/sca-cpp/trunk/components/filedb/filedb.hpp
index 89ff3b8157..39c8aff868 100644
--- a/sca-cpp/trunk/components/filedb/filedb.hpp
+++ b/sca-cpp/trunk/components/filedb/filedb.hpp
@@ -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:
diff --git a/sca-cpp/trunk/components/log/scribe.hpp b/sca-cpp/trunk/components/log/scribe.hpp
index 5237bd0183..1e0ce46511 100644
--- a/sca-cpp/trunk/components/log/scribe.hpp
+++ b/sca-cpp/trunk/components/log/scribe.hpp
@@ -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 {
diff --git a/sca-cpp/trunk/components/nosqldb/tinycdb.hpp b/sca-cpp/trunk/components/nosqldb/tinycdb.hpp
index 0fab1a9854..e26001dc59 100644
--- a/sca-cpp/trunk/components/nosqldb/tinycdb.hpp
+++ b/sca-cpp/trunk/components/nosqldb/tinycdb.hpp
@@ -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)
diff --git a/sca-cpp/trunk/components/queue/qpid.hpp b/sca-cpp/trunk/components/queue/qpid.hpp
index 2651e3a433..4fb4c7a1bd 100644
--- a/sca-cpp/trunk/components/queue/qpid.hpp
+++ b/sca-cpp/trunk/components/queue/qpid.hpp
@@ -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(QpidConnection& qc) {
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();
diff --git a/sca-cpp/trunk/components/sqldb/pgsql.hpp b/sca-cpp/trunk/components/sqldb/pgsql.hpp
index f4da8db220..7dca38b086 100644
--- a/sca-cpp/trunk/components/sqldb/pgsql.hpp
+++ b/sca-cpp/trunk/components/sqldb/pgsql.hpp
@@ -55,9 +55,12 @@ const string pgfailure(PGresult* r, PGconn* conn) {
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)
diff --git a/sca-cpp/trunk/components/webservice/axis2.hpp b/sca-cpp/trunk/components/webservice/axis2.hpp
index c2886edb71..47813ccd6d 100644
--- a/sca-cpp/trunk/components/webservice/axis2.hpp
+++ b/sca-cpp/trunk/components/webservice/axis2.hpp
@@ -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);
diff --git a/sca-cpp/trunk/etc/memgrind b/sca-cpp/trunk/etc/memgrind
index 1a220cd5d2..6fbb76bc30 100755
--- a/sca-cpp/trunk/etc/memgrind
+++ b/sca-cpp/trunk/etc/memgrind
@@ -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
diff --git a/sca-cpp/trunk/kernel/config.hpp b/sca-cpp/trunk/kernel/config.hpp
index 195612428e..f700829fa5 100644
--- a/sca-cpp/trunk/kernel/config.hpp
+++ b/sca-cpp/trunk/kernel/config.hpp
@@ -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.
diff --git a/sca-cpp/trunk/kernel/fstream.hpp b/sca-cpp/trunk/kernel/fstream.hpp
index 99fc51565f..d57de2d76a 100644
--- a/sca-cpp/trunk/kernel/fstream.hpp
+++ b/sca-cpp/trunk/kernel/fstream.hpp
@@ -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;
}
diff --git a/sca-cpp/trunk/modules/http/httpd-debug b/sca-cpp/trunk/modules/http/httpd-debug
new file mode 100755
index 0000000000..93a6bf81d4
--- /dev/null
+++ b/sca-cpp/trunk/modules/http/httpd-debug
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Start httpd server
+here=`readlink -f $0`; here=`dirname $here`
+root=`readlink -f $1`
+
+httpd=`cat $here/httpd.prefix`
+$httpd/bin/httpd -X -E $root/logs/error_log -d $root -f $root/conf/httpd.conf
diff --git a/sca-cpp/trunk/modules/http/httpd-memgrind b/sca-cpp/trunk/modules/http/httpd-memgrind
new file mode 100755
index 0000000000..3219046c22
--- /dev/null
+++ b/sca-cpp/trunk/modules/http/httpd-memgrind
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Start httpd server
+here=`readlink -f $0`; here=`dirname $here`
+root=`readlink -f $1`
+
+httpd=`cat $here/httpd.prefix`
+$here/../../etc/memgrind $httpd/bin/httpd -X -E $root/logs/error_log -d $root -f $root/conf/httpd.conf
diff --git a/sca-cpp/trunk/modules/http/httpd-stop b/sca-cpp/trunk/modules/http/httpd-stop
index 09ac5d035f..cadec1e6a0 100755
--- a/sca-cpp/trunk/modules/http/httpd-stop
+++ b/sca-cpp/trunk/modules/http/httpd-stop
@@ -22,4 +22,4 @@ 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
+$apachectl -k graceful-stop -d $root -f $root/conf/httpd.conf 2>/dev/null
diff --git a/sca-cpp/trunk/modules/http/httpd.hpp b/sca-cpp/trunk/modules/http/httpd.hpp
index a222b38556..b6756c51e3 100644
--- a/sca-cpp/trunk/modules/http/httpd.hpp
+++ b/sca-cpp/trunk/modules/http/httpd.hpp
@@ -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 char* key, const char* value) {
* 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* key, const char* value) {
* 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* key, const char* value) {
* 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;
diff --git a/sca-cpp/trunk/modules/http/mod-openauth.cpp b/sca-cpp/trunk/modules/http/mod-openauth.cpp
index 688f2b0ba8..6917c8862c 100644
--- a/sca-cpp/trunk/modules/http/mod-openauth.cpp
+++ b/sca-cpp/trunk/modules/http/mod-openauth.cpp
@@ -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");
diff --git a/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp b/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
index d2c53b462e..edbc8f3b99 100644
--- a/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
+++ b/sca-cpp/trunk/modules/http/mod-ssltunnel.cpp
@@ -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));
diff --git a/sca-cpp/trunk/modules/java/eval.hpp b/sca-cpp/trunk/modules/java/eval.hpp
index 11e57cb08a..a73c84c64c 100644
--- a/sca-cpp/trunk/modules/java/eval.hpp
+++ b/sca-cpp/trunk/modules/java/eval.hpp
@@ -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;
diff --git a/sca-cpp/trunk/modules/js/eval.hpp b/sca-cpp/trunk/modules/js/eval.hpp
index b7c69a1a0c..6bbbdac0d7 100644
--- a/sca-cpp/trunk/modules/js/eval.hpp
+++ b/sca-cpp/trunk/modules/js/eval.hpp
@@ -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();
}
diff --git a/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp b/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
index 0f190127db..84de8f2d05 100644
--- a/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
+++ b/sca-cpp/trunk/modules/oauth/mod-oauth1.cpp
@@ -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);
diff --git a/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp b/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
index b52967977e..51bd240177 100644
--- a/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
+++ b/sca-cpp/trunk/modules/oauth/mod-oauth2.cpp
@@ -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);
diff --git a/sca-cpp/trunk/modules/python/eval.hpp b/sca-cpp/trunk/modules/python/eval.hpp
index 2dd4b8ba33..bf539faa38 100644
--- a/sca-cpp/trunk/modules/python/eval.hpp
+++ b/sca-cpp/trunk/modules/python/eval.hpp
@@ -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, PyObject* args, unused PyObject* kwds) {
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 *self, PyObject *attrname) {
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(const list<value>&)>& l) {
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 value& expr, PyObject* script) {
// 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());
diff --git a/sca-cpp/trunk/modules/server/mod-eval.hpp b/sca-cpp/trunk/modules/server/mod-eval.hpp
index 8dac21de04..4ee40e51ee 100644
--- a/sca-cpp/trunk/modules/server/mod-eval.hpp
+++ b/sca-cpp/trunk/modules/server/mod-eval.hpp
@@ -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");
diff --git a/sca-cpp/trunk/modules/server/mod-wiring.cpp b/sca-cpp/trunk/modules/server/mod-wiring.cpp
index 0ab61f5af8..b63cd3fb37 100644
--- a/sca-cpp/trunk/modules/server/mod-wiring.cpp
+++ b/sca-cpp/trunk/modules/server/mod-wiring.cpp
@@ -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");