From: David L. <dav...@cs...> - 2000-07-04 01:16:26
|
how does this look? --- message.c 1999/09/19 01:53:21 1.7 +++ message.c 2000/07/04 00:48:09 @@ -45,6 +45,8 @@ #endif /* !CIDICT */ PyTuple_SetItem( entrytuple, 0, PyString_FromString(dn) ); + free(dn); + PyTuple_SetItem( entrytuple, 1, attrdict ); PyList_SetItem( result, entry_index, entrytuple ); @@ -64,7 +66,6 @@ PyMapping_SetItemString( attrdict, attr, valuelist ); } - Py_INCREF( valuelist ); if (bvals != NULL) { int i; for (i=0; bvals[i]; i++) { @@ -74,10 +75,10 @@ bvals[i]->bv_val, bvals[i]->bv_len ); PyList_Append( valuelist, valuestr ); + Py_DECREF(valuestr); } ber_bvecfree(bvals); } - Py_DECREF( valuelist ); } } ldap_msgfree( m ); On Mon, 3 Jul 2000, David Leonard typed thusly: > > these look great! i will have to verify them.. > some C functions incref their args for you, and others don't. there are > docs on which are which. > > i think maybe i should convert things like PyList_Append to PySequence_SetItem > (with an appropriately allocated List). apparently they all have consistent > incref semantics and its much easier to visually check.. > > having problems with cvs at the moment... > > 209.81.8.43: Connection timed out > > On Mon, 3 Jul 2000, David Margrave typed thusly: > > > line 80 on should be: > > > > Py_DECREF( valuelist ); > > } > > free(dn); > > } > > ldap_msgfree( m ); > > return result; > > } > > > > this helps a bit, but something is still leaking memory like > > crazy elsewhere. > > > > I'm not able to do CVS just this moment, so could you add > > that in? > > > > Also in message.c, I added a Py_DECREF for valuestr: > > > > for (i=0; bvals[i]; i++) { > > PyObject *valuestr; > > > > valuestr = PyString_FromStringAndSize( > > bvals[i]->bv_val, bvals[i]->bv_len > > ); > > PyList_Append( valuelist, valuestr ); > > Py_DECREF(valuestr); > > } > > > > I'm not an expert on the python reference counting system, but adding this > > one has cleared up the memory leak (on openldap 1.2.10, compiled without > > caching and without threads. Haven't tried with yet..) I did try adding > > Py_DECREF in a couple other places and got core dumps. For some reason, > > it seems to be valid to do it here. Perhaps because the object in > > question is not a mapping or sequence? Anyhow, memory consumption on my > > program that does thousands of searches no longer goes up monotonically! > > > > Dave > > > > -- David Leonard Dav...@cs... Dept of Comp. Sci. and Elec. Engg _ Room:78-640 Ph:+61 7 336 51187 The University of Queensland |+| http://www.csee.uq.edu.au/~leonard/ QLD 4072 AUSTRALIA ~` '~ E2A24DC6446E5779D7AFC41AA04E6401 |