Author: tridge Date: 2005-08-22 01:51:02 +0000 (Mon, 22 Aug 2005) New Revision: 9464
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9464 Log: fixed a problem with child pointers copied into non-allocated mpr variables. We now use the same free technique as is used for mpr strings, rather than relying on being a child of the variable Modified: branches/SAMBA_4_0/source/lib/appweb/mpr/var.c branches/SAMBA_4_0/source/scripting/ejs/mprutil.c Changeset: Modified: branches/SAMBA_4_0/source/lib/appweb/mpr/var.c =================================================================== --- branches/SAMBA_4_0/source/lib/appweb/mpr/var.c 2005-08-22 00:22:21 UTC (rev 9463) +++ branches/SAMBA_4_0/source/lib/appweb/mpr/var.c 2005-08-22 01:51:02 UTC (rev 9464) @@ -181,6 +181,13 @@ } break; + case MPR_TYPE_PTR: + if (vp->allocatedData) { + vp->allocatedData = 0; + mprFree(vp->ptr); + } + break; + case MPR_TYPE_OBJECT: #if VAR_DEBUG /* @@ -1418,7 +1425,12 @@ case MPR_TYPE_PTR: /* we have to reference here so talloc structures survive a copy */ - dest->ptr = talloc_reference(dest, src->ptr); + if (src->allocatedData) { + dest->ptr = talloc_reference(mprMemCtx(), src->ptr); + dest->allocatedData = 1; + } else { + dest->ptr = src->ptr; + } break; case MPR_TYPE_STRING_CFUNCTION: Modified: branches/SAMBA_4_0/source/scripting/ejs/mprutil.c =================================================================== --- branches/SAMBA_4_0/source/scripting/ejs/mprutil.c 2005-08-22 00:22:21 UTC (rev 9463) +++ branches/SAMBA_4_0/source/scripting/ejs/mprutil.c 2005-08-22 01:51:02 UTC (rev 9464) @@ -369,12 +369,14 @@ } /* - set a pointer in a existing MprVar, making it a child of the property + set a pointer in a existing MprVar, freeing it when the property goes away */ void mprSetPtrChild(struct MprVar *v, const char *propname, const void *p) { mprSetVar(v, propname, mprCreatePtrVar(discard_const(p))); - talloc_steal(mprGetProperty(v, propname, NULL), p); + v = mprGetProperty(v, propname, NULL); + v->allocatedData = 1; + talloc_steal(mprMemCtx(), p); } /*
