You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ac...@apache.org on 2009/11/02 23:08:18 UTC
svn commit: r832134 - in /qpid/trunk/qpid/cpp/src:
qpid/client/SaslFactory.cpp tests/cluster_test.cpp
Author: aconway
Date: Mon Nov 2 22:08:17 2009
New Revision: 832134
URL: http://svn.apache.org/viewvc?rev=832134&view=rev
Log:
Fix leak in SASL code, enable cluster ACL test.
Modified:
qpid/trunk/qpid/cpp/src/qpid/client/SaslFactory.cpp
qpid/trunk/qpid/cpp/src/tests/cluster_test.cpp
Modified: qpid/trunk/qpid/cpp/src/qpid/client/SaslFactory.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/SaslFactory.cpp?rev=832134&r1=832133&r2=832134&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/SaslFactory.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/SaslFactory.cpp Mon Nov 2 22:08:17 2009
@@ -20,6 +20,7 @@
*/
#include "qpid/client/SaslFactory.h"
#include "qpid/client/ConnectionSettings.h"
+#include <map>
#ifdef HAVE_CONFIG_H
# include "config.h"
@@ -326,11 +327,33 @@
}
}
-int getPasswordFromSettings(sasl_conn_t* /*conn*/, void* context, int /*id*/, sasl_secret_t** psecret)
+namespace {
+// Global map of secrest allocated for SASL connections via callback
+// to getPasswordFromSettings. Ensures secrets are freed.
+class SecretsMap {
+ typedef std::map<sasl_conn_t*, void*> Map;
+ Map map;
+ public:
+ void keep(sasl_conn_t* conn, void* secret) {
+ Map::iterator i = map.find(conn);
+ if (i != map.end()) free(i->second);
+ map[conn] = secret;
+ }
+
+ ~SecretsMap() {
+ for (Map::iterator i = map.begin(); i != map.end(); ++i)
+ free(i->second);
+ }
+};
+SecretsMap getPasswordFromSettingsSecrets;
+}
+
+int getPasswordFromSettings(sasl_conn_t* conn, void* context, int /*id*/, sasl_secret_t** psecret)
{
if (context) {
size_t length = ((ConnectionSettings*) context)->password.size();
sasl_secret_t* secret = (sasl_secret_t*) malloc(sizeof(sasl_secret_t) + length);
+ getPasswordFromSettingsSecrets.keep(conn, secret);
secret->len = length;
memcpy(secret->data, ((ConnectionSettings*) context)->password.data(), length);
*psecret = secret;
Modified: qpid/trunk/qpid/cpp/src/tests/cluster_test.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/cluster_test.cpp?rev=832134&r1=832133&r2=832134&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/cluster_test.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/cluster_test.cpp Mon Nov 2 22:08:17 2009
@@ -222,10 +222,6 @@
BOOST_CHECK_EQUAL(c1.session.queueQuery("q1").getQueue(), "");
}
-#if 0
-// FIXME aconway 2009-03-10: This test passes but exposes a memory
-// leak in the SASL client code. Enable it when the leak is fixed.
-
QPID_AUTO_TEST_CASE(testAcl) {
ofstream policyFile("cluster_test.acl");
policyFile << "acl allow foo@QPID create queue name=foo" << endl
@@ -239,6 +235,7 @@
aclLib << getLibPath("ACL_LIB", "../.libs/acl.so");
ClusterFixture::Args args;
prepareArgs(args, durableFlag);
+ args += "--log-enable=critical"; // Supress expected errors
args += "--acl-file", string(cwd) + "/cluster_test.acl",
"--cluster-mechanism", "PLAIN",
"--cluster-username", "cluster",
@@ -253,18 +250,22 @@
foo.session.queueDeclare("foo", arg::durable=durableFlag);
BOOST_CHECK_EQUAL(c0.session.queueQuery("foo").getQueue(), "foo");
- BOOST_CHECK_THROW(foo.session.queueDeclare("bar", arg::durable=durableFlag), framing::NotAllowedException);
+ {
+ ScopedSuppressLogging sl;
+ BOOST_CHECK_THROW(foo.session.queueDeclare("bar", arg::durable=durableFlag), framing::NotAllowedException);
+ }
BOOST_CHECK(c0.session.queueQuery("bar").getQueue().empty());
BOOST_CHECK(c1.session.queueQuery("bar").getQueue().empty());
cluster.add();
Client c2(aclSettings(cluster[2], "c2"), "c2");
- BOOST_CHECK_THROW(foo.session.queueDeclare("bar", arg::durable=durableFlag), framing::NotAllowedException);
+ {
+ ScopedSuppressLogging sl;
+ BOOST_CHECK_THROW(foo.session.queueDeclare("bar", arg::durable=durableFlag), framing::NotAllowedException);
+ }
BOOST_CHECK(c2.session.queueQuery("bar").getQueue().empty());
}
-#endif
-
QPID_AUTO_TEST_CASE(testMessageTimeToLive) {
// Note: this doesn't actually test for cluster race conditions around TTL,
// it just verifies that basic TTL functionality works.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org