Discussion:
[omniORB] DynamicAny memory leak
Sampo Ahokas
2009-01-12 22:04:42 UTC
Permalink
Dear all,

I have been working on a project that uses DII, DSI and DynamicAny
extensively, and it appears that there may be some memory leaks (or I'm
doing things incorrectly, of course...). Setting the members/elements of
DynStruct and DynSequence as DynAny seems to cause a leak.

DynStruct leak details:

DynStructImpl constructor calls setNumComponents(), which causes
elements of pd_components to be initialized with initial values.
DynStructImpl::set_members_as_dyn_any() then just assigns the new value
to pd_components[i], leaking the initial values.

DynSequence leak details:

DynSequenceImpl::set_elements_as_dyn_any(const DynamicAny::DynAnySeq&
as) calls setNumComponents(), and also
assigns the new values to pd_components[i], causing the initial values
constructed by setNumComponents() to be leaked.


Similarly, DynArrayImpl::set_elements_as_dyn_any() might contain the
same leak, but I haven't tried it as I'm not using it.
Attached is a patch that seems to fix the issue here.


Best regards,
Sampo Ahokas
OpenTTCN Ltd

-------------- next part --------------
--- omniORB-4.1.3-clean/src/lib/omniORB/dynamic/dynAny.cc 2008-09-16 12:24:08.000000000 +0300
+++ omniORB-4.1.3/src/lib/omniORB/dynamic/dynAny.cc 2009-01-12 17:32:27.000000000 +0200
@@ -2719,6 +2719,13 @@
daib = ToDynAnyImplBase(newda);
}
daib->attach();
+
+ if(pd_components[i])
+ {
+ pd_components[i]->detach();
+ pd_components[i]->_NP_decrRefCount();
+ }
+
pd_components[i] = daib;
}
pd_curr_index = (pd_n_components == 0) ? -1 : 0;
@@ -4415,6 +4422,13 @@
daib = ToDynAnyImplBase(newda);
}
daib->attach();
+
+ if(pd_components[i])
+ {
+ pd_components[i]->detach();
+ pd_components[i]->_NP_decrRefCount();
+ }
+
pd_components[i] = daib;
}
}
Duncan Grisby
2009-02-02 18:35:51 UTC
Permalink
Post by Sampo Ahokas
I have been working on a project that uses DII, DSI and DynamicAny
extensively, and it appears that there may be some memory leaks (or
I'm doing things incorrectly, of course...). Setting the
members/elements of DynStruct and DynSequence as DynAny seems to cause
a leak.
Yes, you are right. There are leaks in the as_dyn_any functions. I've
applied the fixes you suggest, plus a couple more cases where it could
leak.

Thanks for the bug report / patch,

Duncan.
--
-- Duncan Grisby --
-- ***@grisby.org --
-- http://www.grisby.org --
Loading...