Author: tpot Date: 2005-02-10 03:19:21 +0000 (Thu, 10 Feb 2005) New Revision: 5293
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=5293 Log: Map an empty policy handle to None when creating policy handles, and refuse to accept None as a policy handle when accepting them. Now we don't segfault after running the samr_Shutdown() test. Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i Changeset: Modified: branches/SAMBA_4_0/source/scripting/swig/dcerpc.i =================================================================== --- branches/SAMBA_4_0/source/scripting/swig/dcerpc.i 2005-02-10 03:16:33 UTC (rev 5292) +++ branches/SAMBA_4_0/source/scripting/swig/dcerpc.i 2005-02-10 03:19:21 UTC (rev 5293) @@ -182,14 +182,31 @@ $result = PyLong_FromLong(*$1); } +%typemap(in) struct policy_handle * { + + if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, + SWIG_POINTER_EXCEPTION)) == -1) + return NULL; + + if ($1 == NULL) { + PyErr_SetString(PyExc_TypeError, "None is not a valid policy handle"); + return NULL; + } +} + /* When returning a policy handle to Python we need to make a copy of as the talloc context it is created under is destroyed after the wrapper function returns. TODO: Fix memory leak created here. */ %typemap(out) struct policy_handle * { - struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle)); - memcpy(temp, $1, sizeof(struct policy_handle)); - $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0); + if ($1) { + struct policy_handle *temp = (struct policy_handle *)malloc(sizeof(struct policy_handle)); + memcpy(temp, $1, sizeof(struct policy_handle)); + $result = SWIG_NewPointerObj(temp, SWIGTYPE_p_policy_handle, 0); + } else { + Py_INCREF(Py_None); + $result = Py_None; + } } %{