You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-dev@logging.apache.org by Russel Kubik <ru...@3d-p.com> on 2015/03/27 22:22:52 UTC

log4cxx shared library - countless memory leaks

Hi,

I am using the latest log4cxx library (0.10.0) on Debian (log4cxx10-dev)
and find that any application I use with this library will result in the
following valgrind errors: http://pastebin.com/ypt4ZH4i

If I strip log4cxx out of the source and re-run valgrind, it will pass
without any errors.

Am I using the library wrong or is there an issue with the underlying
implementation?

Sample usage:

void Log::toConsole(Level level)
{
    log4cxx::ConsoleAppenderPtr consoleAppender(new
log4cxx::ConsoleAppender());
    consoleAppender->setLayout(new
log4cxx::PatternLayout(LOG_OUTPUT_FORMAT));
    log4cxx::helpers::Pool pool;
    consoleAppender->activateOptions(pool);
    consoleAppender->setThreshold(LOG_LEVEL_LOOKUP[level]);
    log4cxx::Logger::getRootLogger()->addAppender(consoleAppender);
}

void Log::toFile(std::string log_path, Level level, bool append, bool
rotate, unsigned int max_backups, int max_size)
{
    if (log_path.empty())
        throw LoggerException("Log filepath cannot be empty.");

    if (rotate) {
        log4cxx::RollingFileAppenderPtr rollingFileAppender(new
log4cxx::RollingFileAppender());
        rollingFileAppender->setLayout(new
log4cxx::PatternLayout(LOG_OUTPUT_FORMAT));
        rollingFileAppender->setFile(log_path);
        rollingFileAppender->setAppend(append);
        rollingFileAppender->setMaxBackupIndex(max_backups);
        rollingFileAppender->setMaximumFileSize(max_size);
        log4cxx::helpers::Pool pool;
        rollingFileAppender->activateOptions(pool);
        rollingFileAppender->setThreshold(LOG_LEVEL_LOOKUP[level]);
        log4cxx::Logger::getRootLogger()->addAppender(rollingFileAppender);
    } else {
        log4cxx::FileAppenderPtr fileAppender(new log4cxx::FileAppender());
        fileAppender->setLayout(new
log4cxx::PatternLayout(LOG_OUTPUT_FORMAT));
        fileAppender->setFile(log_path);
        fileAppender->setAppend(append);
        fileAppender->setThreshold(LOG_LEVEL_LOOKUP[level]);
        log4cxx::Logger::getRootLogger()->addAppender(fileAppender);
    }
}

void Log::setLevel(Level level)
{
    log4cxx::Logger::getRootLogger()->setLevel(LOG_LEVEL_LOOKUP[level]);
}

Re: log4cxx shared library - countless memory leaks

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Russel Kubik,
am Freitag, 27. März 2015 um 22:22 schrieben Sie:

> I am using the latest log4cxx library (0.10.0) on Debian
> (log4cxx10-dev)

This version is the latest official release currently, but a lot of
bug fixes have been applied to trunk in the meanwhile. You should at
least test trunk and see if it changes anything.

> Am I using the library wrong or is there an issue with the underlying implementation?

There are still issues open of course, but not so many specially about
Valgrind reporting memory leaks. Additionally to trying with a current
trunk, I would consider using a configuration file to see if this
makes any difference to your approach with creating objects on your
own.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail: Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow