From: Roger U. <ru...@us...> - 2007-08-17 08:41:35
|
Update of /cvsroot/pywin32/pywin32/win32/src/win32net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22522/win32/src/win32net Modified Files: win32netmodule.cpp Log Message: Fix a couple of 64-bit issues and a memory leak Index: win32netmodule.cpp =================================================================== RCS file: /cvsroot/pywin32/pywin32/win32/src/win32net/win32netmodule.cpp,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** win32netmodule.cpp 24 May 2007 06:01:06 -0000 1.24 --- win32netmodule.cpp 17 Aug 2007 08:41:35 -0000 1.25 *************** *** 394,402 **** PyObject *obServer, *obGroup, *obData; PyObject *ret = NULL; DWORD level; DWORD err = 0; BYTE *buf = NULL; BYTE **ppTempObjects = NULL; ! int i, numEntries; PyNET_STRUCT *pI; if (!PyArg_ParseTuple(args, "OOiO", &obServer, &obGroup, &level, &obData)) --- 394,403 ---- PyObject *obServer, *obGroup, *obData; PyObject *ret = NULL; + PyObject *members_tuple=NULL; DWORD level; DWORD err = 0; BYTE *buf = NULL; BYTE **ppTempObjects = NULL; ! DWORD i, numEntries; PyNET_STRUCT *pI; if (!PyArg_ParseTuple(args, "OOiO", &obServer, &obGroup, &level, &obData)) *************** *** 409,426 **** goto done; ! if (!PySequence_Check(obData)) { PyErr_SetString(PyExc_TypeError, "Data must be a sequence of dictionaries"); goto done; } - numEntries = PySequence_Length(obData); ppTempObjects = new BYTE *[numEntries]; memset(ppTempObjects, 0, sizeof(BYTE *) * numEntries); for (i=0;i<numEntries;i++) { ! PyObject *sub = PySequence_GetItem(obData, i); ! if (sub==NULL) goto done; ! if (!PyObject_AsNET_STRUCT(sub, pI, ppTempObjects+i)) { ! Py_DECREF(sub); goto done; - } } // OK - all objects are ok, and we are holding the buffers. --- 410,425 ---- goto done; ! ! members_tuple=PyWinSequence_Tuple(obData, &numEntries); ! if (members_tuple==NULL) { PyErr_SetString(PyExc_TypeError, "Data must be a sequence of dictionaries"); goto done; } ppTempObjects = new BYTE *[numEntries]; memset(ppTempObjects, 0, sizeof(BYTE *) * numEntries); for (i=0;i<numEntries;i++) { ! PyObject *sub = PyTuple_GET_ITEM(members_tuple, i); ! if (!PyObject_AsNET_STRUCT(sub, pI, ppTempObjects+i)) goto done; } // OK - all objects are ok, and we are holding the buffers. *************** *** 445,448 **** --- 444,448 ---- PyWinObject_FreeWCHAR(szServer); PyWinObject_FreeWCHAR(szGroup); + Py_XDECREF(members_tuple); if (ppTempObjects) { for (i=0;i<numEntries;i++) { *************** *** 836,842 **** PyObject *obServer, *obGroup, *obData; PyObject *ret = NULL; DWORD err = 0; BYTE *buf = NULL; ! int i, numEntries; DWORD level = 3; LOCALGROUP_MEMBERS_INFO_3 *plgrminfo; --- 836,843 ---- PyObject *obServer, *obGroup, *obData; PyObject *ret = NULL; + PyObject *members_tuple=NULL; DWORD err = 0; BYTE *buf = NULL; ! DWORD i, numEntries; DWORD level = 3; LOCALGROUP_MEMBERS_INFO_3 *plgrminfo; *************** *** 849,875 **** goto done; ! if (!PySequence_Check(obData)) { PyErr_SetString(PyExc_TypeError, "Data must be a sequence of dictionaries"); goto done; } ! ! numEntries = PySequence_Length(obData); ! plgrminfo = new LOCALGROUP_MEMBERS_INFO_3[numEntries]; // XXX - todo - we should allow a list of LOCALGROUP_MEMBER_INFO items *or* strings memset(plgrminfo, 0, sizeof(LOCALGROUP_MEMBERS_INFO_3) * numEntries); for (i = 0; i < numEntries; i++) { ! PyObject *sub = PySequence_GetItem(obData, i); ! if (sub==NULL) ! goto done; ! PyWinObject_AsWCHAR(sub, &plgrminfo[i].lgrmi3_domainandname); ! if (!plgrminfo[i].lgrmi3_domainandname) { ! Py_DECREF(sub); goto done; - } } ! Py_BEGIN_ALLOW_THREADS ! err = NetLocalGroupDelMembers(szServer, szGroup, 3, (BYTE *)plgrminfo, numEntries); ! Py_END_ALLOW_THREADS if (err) { ReturnNetError("NetLocalGroupDelMembers", err); --- 850,874 ---- goto done; ! members_tuple=PyWinSequence_Tuple(obData, &numEntries); ! if (members_tuple==NULL) { PyErr_SetString(PyExc_TypeError, "Data must be a sequence of dictionaries"); goto done; } ! plgrminfo = new LOCALGROUP_MEMBERS_INFO_3[numEntries]; ! if (plgrminfo==NULL){ ! PyErr_NoMemory(); ! goto done; ! } // XXX - todo - we should allow a list of LOCALGROUP_MEMBER_INFO items *or* strings memset(plgrminfo, 0, sizeof(LOCALGROUP_MEMBERS_INFO_3) * numEntries); for (i = 0; i < numEntries; i++) { ! PyObject *sub = PyTuple_GET_ITEM(members_tuple, i); ! if (!PyWinObject_AsWCHAR(sub, &plgrminfo[i].lgrmi3_domainandname)) goto done; } ! Py_BEGIN_ALLOW_THREADS ! err = NetLocalGroupDelMembers(szServer, szGroup, 3, (BYTE *)plgrminfo, numEntries); ! Py_END_ALLOW_THREADS if (err) { ReturnNetError("NetLocalGroupDelMembers", err); *************** *** 883,892 **** PyWinObject_FreeWCHAR(szServer); PyWinObject_FreeWCHAR(szGroup); if (plgrminfo) { for (i=0;i<numEntries;i++) { ! if (plgrminfo[i].lgrmi3_domainandname) { ! PyWinObject_FreeWCHAR(plgrminfo[i].lgrmi3_domainandname); ! } } } return ret; --- 882,893 ---- PyWinObject_FreeWCHAR(szServer); PyWinObject_FreeWCHAR(szGroup); + Py_XDECREF(members_tuple); if (plgrminfo) { for (i=0;i<numEntries;i++) { ! if (plgrminfo[i].lgrmi3_domainandname) { ! PyWinObject_FreeWCHAR(plgrminfo[i].lgrmi3_domainandname); ! } } + delete [] plgrminfo; } return ret; *************** *** 1116,1120 **** {"NetUserModalsGet", PyNetUserModalsGet, 1}, // @pymeth NetUserModalsGet|Retrieves global user information on a server. ! {"NetUserModalsSet", PyNetUserModalsSet, 1}, // @pymeth NetUserModalsSet|Sets global user information on a server. {"NetWkstaUserEnum", PyNetWkstaUserEnum, 1}, // @pymeth NetWkstaUserEnum|Retrieves information about all users currently logged on to the workstation. --- 1117,1121 ---- {"NetUserModalsGet", PyNetUserModalsGet, 1}, // @pymeth NetUserModalsGet|Retrieves global user information on a server. ! {"NetUserModalsSet", PyNetUserModalsSet, 1}, // @pymeth NetUserModalsSet|Sets global user information on a server. {"NetWkstaUserEnum", PyNetWkstaUserEnum, 1}, // @pymeth NetWkstaUserEnum|Retrieves information about all users currently logged on to the workstation. |