[pywin32-checkins] pywin32/win32/src PySECURITY_DESCRIPTOR.cpp,1.8,1.9
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: <mha...@us...> - 2003-07-29 07:06:08
|
Update of /cvsroot/pywin32/pywin32/win32/src
In directory sc8-pr-cvs1:/tmp/cvs-serv30686
Modified Files:
PySECURITY_DESCRIPTOR.cpp
Log Message:
Fix memory leaks - from Roger Upole, from:
[ 732056 ] Fix memory leak in security descriptor functions
Index: PySECURITY_DESCRIPTOR.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/win32/src/PySECURITY_DESCRIPTOR.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PySECURITY_DESCRIPTOR.cpp 10 Mar 2003 01:18:16 -0000 1.8
--- PySECURITY_DESCRIPTOR.cpp 29 Jul 2003 06:47:58 -0000 1.9
***************
*** 50,58 ****
void FreeAbsoluteSD(PSECURITY_DESCRIPTOR psd)
{
! FreeSD_DACL(psd);
! FreeSD_SACL(psd);
! FreeSD_Owner(psd);
! FreeSD_Group(psd);
! free(psd);
}
--- 50,58 ----
void FreeAbsoluteSD(PSECURITY_DESCRIPTOR psd)
{
! FreeSD_DACL(psd);
! FreeSD_SACL(psd);
! FreeSD_Owner(psd);
! FreeSD_Group(psd);
! free(psd);
}
***************
*** 162,192 ****
{
PSECURITY_DESCRIPTOR psd_absolute = NULL;
! PACL pdacl;
! PACL psacl;
! PSID powner;
! PSID pgroup;
! DWORD origsdsize = SECURITY_DESCRIPTOR_MIN_LENGTH;
! DWORD origdaclsize = sizeof(ACL);
! DWORD origsaclsize = sizeof(ACL);
! DWORD origownersize = sizeof(SID);
! DWORD origgroupsize = sizeof(SID);
! DWORD sdsize,daclsize,saclsize,ownersize,groupsize;
!
! sdsize = origsdsize;
! daclsize = origdaclsize;
! saclsize = origsaclsize;
! ownersize = origownersize;
! groupsize = origgroupsize;
psd_absolute = malloc(sdsize);
ZeroMemory(psd_absolute,sdsize);
::InitializeSecurityDescriptor(psd_absolute,SECURITY_DESCRIPTOR_REVISION);
- pdacl = (ACL *)malloc(daclsize);
- psacl = (ACL *)malloc(saclsize);
- powner = malloc(ownersize);
- pgroup = malloc(groupsize);
BOOL resize = FALSE;
! if(MakeAbsoluteSD(psd_relative, psd_absolute, &sdsize,
pdacl, &daclsize, psacl, &saclsize,
powner, &ownersize, pgroup, &groupsize)){
--- 162,182 ----
{
PSECURITY_DESCRIPTOR psd_absolute = NULL;
! PACL pdacl = NULL;
! PACL psacl = NULL;
! PSID powner = NULL;
! PSID pgroup = NULL;
! DWORD sdsize = SECURITY_DESCRIPTOR_MIN_LENGTH;
! DWORD origsdsize = SECURITY_DESCRIPTOR_MIN_LENGTH;
! DWORD daclsize = 0;
! DWORD saclsize = 0;
! DWORD ownersize = 0;
! DWORD groupsize = 0;
psd_absolute = malloc(sdsize);
ZeroMemory(psd_absolute,sdsize);
::InitializeSecurityDescriptor(psd_absolute,SECURITY_DESCRIPTOR_REVISION);
BOOL resize = FALSE;
! if(MakeAbsoluteSD(psd_relative, psd_absolute, &sdsize,
pdacl, &daclsize, psacl, &saclsize,
powner, &ownersize, pgroup, &groupsize)){
***************
*** 200,221 ****
::InitializeSecurityDescriptor(psd_absolute,SECURITY_DESCRIPTOR_REVISION);
}
! if (daclsize > origdaclsize){
resize = TRUE;
- free(pdacl);
pdacl = (ACL *)malloc(daclsize);
}
! if (saclsize > origsaclsize){
resize = TRUE;
- free(psacl);
psacl = (ACL *)malloc(saclsize);
}
! if (ownersize > origownersize){
resize = TRUE;
- free(powner);
powner = (SID *)malloc(ownersize);
}
! if (groupsize > origgroupsize){
resize = TRUE;
- free(pgroup);
pgroup = (SID *)malloc(groupsize);
}
--- 190,207 ----
::InitializeSecurityDescriptor(psd_absolute,SECURITY_DESCRIPTOR_REVISION);
}
! if (daclsize > 0){
resize = TRUE;
pdacl = (ACL *)malloc(daclsize);
}
! if (saclsize > 0){
resize = TRUE;
psacl = (ACL *)malloc(saclsize);
}
! if (ownersize > 0){
resize = TRUE;
powner = (SID *)malloc(ownersize);
}
! if (groupsize > 0){
resize = TRUE;
pgroup = (SID *)malloc(groupsize);
}
***************
*** 229,233 ****
powner, &ownersize, pgroup, &groupsize)){
*ppsd_absolute = psd_absolute;
- DWORD sdsize=::GetSecurityDescriptorLength(psd_absolute);
return TRUE;
}
--- 215,218 ----
***************
*** 267,271 ****
if (!::InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION))
return PyWin_SetAPIError("InitializeSecurityDescriptor");
! // above always returns in absolute format, change back to self-relative
if (_MakeSelfRelativeSD(psd,&psd_relative))
if (This->SetSD(psd_relative))
--- 252,256 ----
if (!::InitializeSecurityDescriptor(psd, SECURITY_DESCRIPTOR_REVISION))
return PyWin_SetAPIError("InitializeSecurityDescriptor");
! // above always returns in absolute format, change back to self-relative
if (_MakeSelfRelativeSD(psd,&psd_relative))
if (This->SetSD(psd_relative))
***************
*** 285,289 ****
PySECURITY_DESCRIPTOR *This = (PySECURITY_DESCRIPTOR *)self;
PSECURITY_DESCRIPTOR psd=NULL, psd_relative=NULL;
- DWORD sdsize=0,required_size=0,aclsize=0;
BOOL bDaclPresent, bDaclDefaulted;
PACL pdacl;
--- 270,273 ----
***************
*** 296,300 ****
// @pyparm int|bDaclDefaulted||A flag indicating if the SE_DACL_DEFAULTED flag should be set.
! PSECURITY_DESCRIPTOR obpsd = This->GetSD();
// will alway be in relative format in python object, convert to absolute
if (!_MakeAbsoluteSD(obpsd, &psd))
--- 280,284 ----
// @pyparm int|bDaclDefaulted||A flag indicating if the SE_DACL_DEFAULTED flag should be set.
! PSECURITY_DESCRIPTOR obpsd = This->GetSD();
// will alway be in relative format in python object, convert to absolute
if (!_MakeAbsoluteSD(obpsd, &psd))
***************
*** 336,340 ****
PACL psacl;
BOOL bSaclPresent, bSaclDefaulted;
- DWORD sdsize=0,required_size=0,aclsize=0;
// @pyparm int|bSaclPresent||A flag indicating if SACL is to be used. If false, last 2 parms are ignored.
// @pyparm <o PyACL>|SACL||The SACL to set in the security descriptor
--- 320,323 ----
***************
*** 345,349 ****
return NULL;
! PSECURITY_DESCRIPTOR obpsd = This->GetSD();
if (!_MakeAbsoluteSD(obpsd,&psd))
goto done;
--- 328,332 ----
return NULL;
! PSECURITY_DESCRIPTOR obpsd = This->GetSD();
if (!_MakeAbsoluteSD(obpsd,&psd))
goto done;
***************
*** 411,415 ****
PySECURITY_DESCRIPTOR *This = (PySECURITY_DESCRIPTOR *)self;
PSID NewOwnerSid = NULL;
! PySID *obNewOwnerSid = NULL;
PyObject *ret = NULL;
if (!PyArg_ParseTuple(args, "Oi:SetSecurityDescriptorOwner", &obNewOwnerSid, &bOwnerDefaulted))
--- 394,398 ----
PySECURITY_DESCRIPTOR *This = (PySECURITY_DESCRIPTOR *)self;
PSID NewOwnerSid = NULL;
! PyObject *obNewOwnerSid = NULL;
PyObject *ret = NULL;
if (!PyArg_ParseTuple(args, "Oi:SetSecurityDescriptorOwner", &obNewOwnerSid, &bOwnerDefaulted))
***************
*** 433,437 ****
done:
! if (psd){
FreeSD_DACL(psd);
FreeSD_SACL(psd);
--- 416,420 ----
done:
! if (psd != NULL){
FreeSD_DACL(psd);
FreeSD_SACL(psd);
***************
*** 440,444 ****
free(psd);
}
! if (psd_relative)
free(psd_relative);
Py_XINCREF(ret);
--- 423,427 ----
free(psd);
}
! if (psd_relative != NULL)
free(psd_relative);
Py_XINCREF(ret);
***************
*** 456,460 ****
PSECURITY_DESCRIPTOR psd_relative = NULL;
PSID NewGroupSid = NULL;
! PySID *obNewGroupSid = NULL;
PyObject *ret = NULL;
--- 439,443 ----
PSECURITY_DESCRIPTOR psd_relative = NULL;
PSID NewGroupSid = NULL;
! PyObject *obNewGroupSid = NULL;
PyObject *ret = NULL;
***************
*** 478,482 ****
done:
! if (psd){
FreeSD_DACL(psd);
FreeSD_SACL(psd);
--- 461,465 ----
done:
! if (psd != NULL){
FreeSD_DACL(psd);
FreeSD_SACL(psd);
***************
*** 485,489 ****
// *Don't* free group, will still be owned by passed in PySID
}
! if (psd_relative)
free(psd_relative);
Py_XINCREF(ret);
--- 468,472 ----
// *Don't* free group, will still be owned by passed in PySID
}
! if (psd_relative != NULL)
free(psd_relative);
Py_XINCREF(ret);
***************
*** 591,595 ****
if (!::GetSecurityDescriptorControl(psd, &Control, &dwRevision))
return PyWin_SetAPIError("GetSecurityDescriptorControl");
! return Py_BuildValue("(ii)", Control, dwRevision);
}
--- 574,578 ----
if (!::GetSecurityDescriptorControl(psd, &Control, &dwRevision))
return PyWin_SetAPIError("GetSecurityDescriptorControl");
! return Py_BuildValue("(ii)", Control, dwRevision);
}
|