r2842 - in trunk/libmutil: include/libmutil source
erik at minisip.org
erik at minisip.org
Tue Oct 17 21:49:10 CEST 2006
Author: erik
Date: 2006-10-17 21:49:09 +0200 (Tue, 17 Oct 2006)
New Revision: 2842
Modified:
trunk/libmutil/include/libmutil/Exception.h
trunk/libmutil/source/Exception.cxx
Log:
* Bug fix: Fixed copy constructor in the libmutil Exception class.
The Exception class has an attribute that is dynamically allocated
using "new" in the constructor, and deleted in the destructor.
We did not have a copy constructor therefore we did a double free
when ever the copy constructor was used (for example if an example was
passed as an argument to a function), as in the following example:
#include<libmutil/Exception.h>
void f(Exception e){ }
int main(){
Exception e("a description");
f(e);
return 0;
}
Modified: trunk/libmutil/include/libmutil/Exception.h
===================================================================
--- trunk/libmutil/include/libmutil/Exception.h 2006-10-17 19:37:59 UTC (rev 2841)
+++ trunk/libmutil/include/libmutil/Exception.h 2006-10-17 19:49:09 UTC (rev 2842)
@@ -59,6 +59,8 @@
* using the "what()" method.
*/
Exception(char const* what);
+
+ Exception(const Exception &)
~Exception() throw ();
Modified: trunk/libmutil/source/Exception.cxx
===================================================================
--- trunk/libmutil/source/Exception.cxx 2006-10-17 19:37:59 UTC (rev 2841)
+++ trunk/libmutil/source/Exception.cxx 2006-10-17 19:49:09 UTC (rev 2842)
@@ -30,6 +30,14 @@
#endif
}
+Exception::Exception(const Exception &e):
+ msg(e.msg),
+ stackDepth(e.stackDepth)
+{
+ stack = new void*[MAX_STACK_TRACE_DEPTH];
+ memcpy(stack, d.stack, MAX_STACK_TRACE_DEPTH*sizeof(void*));
+}
+
/**
* We use "backtrace" in libc to get find out what the
* stack looks like.
More information about the Minisip-devel
mailing list