Bug 81247 - log4cxx-0.9.7 adjustments related to missing virtual destructors and wrong deletition of new objects using simple delete
Bug#: 81247 Product:  Gentoo Linux Version: unspecified Platform: x86
OS/Version: Linux Status: RESOLVED Severity: normal Priority: P2
Resolution: FIXED Assigned To: ka0ttic@gentoo.org Reported By: gprtg@hck.sk
Component: Ebuilds
URL: 
Summary: log4cxx-0.9.7 adjustments related to missing virtual destructors and wrong deletition of new objects using simple delete
Keywords:  
Status Whiteboard: 
Opened: 2005-02-08 08:47 0000
Description:   Opened: 2005-02-08 08:47 0000
2 issues:
(1) While compiling applications that use log4cxx library, I get bunch of warnings when I specify   -Wall warning option to g++ (g++-3.3.X, maybe also older ones...) - something related to usage of virtual functions in classes that do not have virtual destructors (sorry, I don't have original warning listing...).

(2) When using valgrind (memory debugger, version 2.2.0, but older versions complain as well), I get errors regarding mismatched delete/delete[] on memory.

Reproducible: Always
Steps to Reproduce:
1. prepare some testing file that uses log4cxx, include log4cxx/logger.h
2. compile with -Wall flags
3. run using valgrind and check error output

Actual Results:  
Basically nothing, just got bunch of warnings which can cause I miss other, more
important warnings. And there is a memory leak when deleting with simple delete
(and not delete[]) - it's not fatal since it's at the aplication exit, so
nothing fatal, actually.

Expected Results:  
no warnings from g++, no memory leak reports from valgrind.

All the problems described above can be solved by this patch, it's a patch
against original log4cxx-0.9.7 as you get by untgzing original distribution tarball:

diff -ur log4cxx-0.9.7/include/log4cxx/helpers/class.h
log4cxx-0.9.7-adjusted/include/log4cxx/helpers/class.h
--- log4cxx-0.9.7/include/log4cxx/helpers/class.h	2004-05-10 14:41:02.000000000
+0200
+++ log4cxx-0.9.7-adjusted/include/log4cxx/helpers/class.h	2004-09-10
16:41:28.000000000 +0200
@@ -53,6 +53,7 @@
 		{
 		public:
 			Class(const String& name);
+			virtual ~Class() {};
 			virtual ObjectPtr newInstance() const;
 			const String& toString() const;
 			const String& getName() const;
diff -ur log4cxx-0.9.7/src/stringtokenizer.cpp
log4cxx-0.9.7-adjusted/src/stringtokenizer.cpp
--- log4cxx-0.9.7/src/stringtokenizer.cpp	2004-05-10 14:38:08.000000000 +0200
+++ log4cxx-0.9.7-adjusted/src/stringtokenizer.cpp	2004-09-17 19:58:37.000000000
+0200
@@ -39,7 +39,7 @@
 
 StringTokenizer::~StringTokenizer()
 {
-	delete this->str;
+	delete[] this->str;
 }
 
 bool StringTokenizer::hasMoreTokens() const

------- Comment #1 From Juraj Hercek 2005-02-08 08:49:55 0000 -------
Created an attachment (id=50738) [details]
The fix for virtual destructor + correct delete[] operator

------- Comment #2 From nathanegge@yahoo.com 2005-03-15 16:40:53 0000 -------
I am seeing this problem currently.  Any idea when this patch will be applied
to the ebuild?

------- Comment #3 From Aaron Walker (RETIRED) 2005-03-16 03:12:21 0000 -------
Juraj, apologies are due.  I thought I had commented on this bug when it first
came in but was mistaken.

negge@vt.edu
> I am seeing this problem currently.  Any idea when this patch will be applied to the ebuild?

Sure, how about now :)  I would have done this a lot sooner had I not forgotten
about it.

-r2 is in cvs.