Hi,

I was trying to compile chromium today on Linux and I got this error.
This error occurred because of -Werror CFLAG set in the Makefile. I
remedied by writing a one-liner to delete all occurrences of -Werror
from CFLAGS in all Makefiles.

However, this error intrigued me. I saw through the code and the
classes in question have declared virtual methods but haven't declared
a destructor. In that case, the compiler generates the destructor.


Base *b = new Sub();
delete b;

To the best of my knowledge, if Base is the class which defines
virtual methods but non-virtual destructor, delete can cause a memory
leak if Sub happens to be taking more memory than Base. I think  that
the destructor for a class with virtual methods has either to be
"public virtual" or "protected non-virtual" for the proper freeing of
memory.


Would someone help me clarify this?

I know there might be some scenarios where this can be done
intentionally but looks like there are more arguments for adding a
virtual destructor than not adding one. I see that this is done for
the Delegates. Also, if this is one of the intended special cases, can
someone explain how to compile chromium  then? Deleting -Werror from
CFLAGS is an ugly hack at best.


Rahul

-- 
Chromium Developers mailing list: chromium-dev@googlegroups.com 
View archives, change email options, or unsubscribe: 
    http://groups.google.com/group/chromium-dev

Reply via email to