svn rev #25409: tools/gssmonger/trunk/gssmaster/
ghudson@MIT.EDU
ghudson at MIT.EDU
Mon Oct 24 01:01:59 EDT 2011
http://src.mit.edu/fisheye/changelog/krb5/?cs=25409
Commit By: ghudson
Log Message:
Fix double-free in log4cpp glue.
Category::setAppender transfers ownership of the pointer to the
category, so freeing it at process end is a double-free.
Since we're not freeing app and appConsole at the end, we don't need
to keep around global pointers to them, and we can just use a static
boolean to keep track of whether they've been added to the root
category.
Category::setAppender is deprecated, so use addAppender instead (same
semantics for a non-null appender).
Changed Files:
U tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp
Modified: tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp
===================================================================
--- tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp 2011-10-24 04:40:28 UTC (rev 25408)
+++ tools/gssmonger/trunk/gssmaster/ezlog_log4cpp.cpp 2011-10-24 05:01:58 UTC (rev 25409)
@@ -152,7 +152,6 @@
};
//Category *cat = NULL;
static CatStack *cats = NULL;
-static Appender *app = NULL, *appConsole = NULL;
// Start a new log4cpp log
EZLOGAPI ezStartBlock(IN OPTIONAL HANDLE OldLevel,
@@ -161,16 +160,17 @@
IN OPTIONAL ULONG LogLevel,
IN LPEZSTR LogString,
...) {
+ static bool inited = false;
- if (app == NULL) {
- app = new FileAppender("FileAppender", "gssmaster.log");
- app->setLayout(new BasicLayout());
- Category::getRoot().setAppender(app);
+ if (!inited) {
+ Appender *app = new FileAppender("FileAppender", "gssmaster.log");
+ app->setLayout(new BasicLayout());
+ Category::getRoot().addAppender(app);
+ Appender *appConsole = new OstreamAppender("OstreamAppender",
+ &(std::cout));
+ Category::getRoot().addAppender(appConsole);
+ inited = true;
}
- if (appConsole == NULL) {
- appConsole = new OstreamAppender("OstreamAppender", &(std::cout));
- Category::getRoot().setAppender(appConsole);
- }
static ULONG BlockCounter = 0;
@@ -281,10 +281,6 @@
// Close the log4cpp log
EZLOGAPI ezCloseLog( IN OPTIONAL ULONG flags, ... ) {
Category::shutdown();
- delete app;
- app = NULL;
- delete appConsole;
- appConsole = NULL;
}
// Open the log4cpp log
More information about the cvs-krb5
mailing list