summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2014-02-06 20:17:26 +0000
committerAlan Conway <aconway@apache.org>2014-02-06 20:17:26 +0000
commitc53117656a1ee4e1e7e5419a591f782f7ddfba7f (patch)
tree0fb9014563e9b39436f1a3b173e0d99c99a760e7
parentfdbfa5fba57db0802a9cbff5dc928f2679761c49 (diff)
downloadqpid-python-c53117656a1ee4e1e7e5419a591f782f7ddfba7f.tar.gz
NO-JIRA: Get rid of valgrind "rechable" block in logging statements.
Each logging statement was allocating and not freeing a string, generating a huge number of harmless but annoying "blocks are still reachable". Fixed so the strings are freed at static destructor time. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1565431 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/cpp/src/qpid/log/Logger.cpp2
-rw-r--r--qpid/cpp/src/qpid/log/Statement.cpp49
-rw-r--r--qpid/cpp/src/qpid/log/Statement.h1
3 files changed, 14 insertions, 38 deletions
diff --git a/qpid/cpp/src/qpid/log/Logger.cpp b/qpid/cpp/src/qpid/log/Logger.cpp
index 8dd970c3b9..7b1e22f80c 100644
--- a/qpid/cpp/src/qpid/log/Logger.cpp
+++ b/qpid/cpp/src/qpid/log/Logger.cpp
@@ -106,7 +106,7 @@ void Logger::log(const Statement& s, const std::string& msg) {
os << s.file << ":";
if (flags&LINE)
os << dec << s.line << ":";
- if (flags&FUNCTION)
+ if ((flags&FUNCTION) && s.function)
os << s.function << ":";
if (flags & (FILE|LINE|FUNCTION))
os << " ";
diff --git a/qpid/cpp/src/qpid/log/Statement.cpp b/qpid/cpp/src/qpid/log/Statement.cpp
index e91756cb9a..d70dbc501a 100644
--- a/qpid/cpp/src/qpid/log/Statement.cpp
+++ b/qpid/cpp/src/qpid/log/Statement.cpp
@@ -144,54 +144,29 @@ void Statement::log(const std::string& message) {
Statement::Initializer::Initializer(Statement& s) : statement(s) {
- // QPID-3891
+ // QPID-3891:
// From the given BOOST_CURRENT_FUNCTION name extract only the
// namespace-qualified-functionName, skipping return and calling args.
// Given:
// <possible return value type> qpid::name::space::Function(args)
// Return:
// "qpid::name::space::Function".
- if (s.function != NULL) {
- bool foundOParen(false);
- const char * opPtr;
- for (opPtr = s.function; *opPtr != '\0'; opPtr++) {
- if (*opPtr == '(') {
- foundOParen = true;
- break;
- }
- }
-
- if (foundOParen) {
- const char * bPtr = opPtr;
- for (bPtr = opPtr; bPtr > s.function; bPtr--) {
- if (bPtr[-1] == ' ') {
- break;
- }
- }
-
- size_t nStoreSize = opPtr - bPtr;
- if (nStoreSize > 0) {
- // Note: the struct into which this name is stored
- // is static and is never deleted.
- char * nStore = new char[nStoreSize + 1];
- std::copy (bPtr, opPtr, nStore);
- nStore[nStoreSize] = '\0';
-
- s.function = nStore;
- } else {
- // Ignore zero length name
- }
- } else {
- // No name found - do nothing
- }
- } else {
- // no function-name pointer to process
+ if (s.function) {
+ const char* end = s.function + strlen(s.function);
+ const char* fEnd = std::find(s.function, end, '(');
+ typedef std::reverse_iterator<const char*> Reverse;
+ const char* fBegin = find(Reverse(fEnd), Reverse(s.function), ' ').base();
+ s.function = ::strndup(fBegin, fEnd-fBegin);
}
-
Statement::categorize(s);
Logger::instance().add(s);
}
+Statement::Initializer::~Initializer() {
+ ::free(const_cast<char*>(statement.function));
+ statement.function = 0;
+}
+
namespace {
const char* names[LevelTraits::COUNT] = {
diff --git a/qpid/cpp/src/qpid/log/Statement.h b/qpid/cpp/src/qpid/log/Statement.h
index 20fd3745b6..410ffaaa3d 100644
--- a/qpid/cpp/src/qpid/log/Statement.h
+++ b/qpid/cpp/src/qpid/log/Statement.h
@@ -114,6 +114,7 @@ struct Statement {
struct Initializer {
QPID_COMMON_EXTERN Initializer(Statement& s);
+ QPID_COMMON_EXTERN ~Initializer();
Statement& statement;
};
};