From 71ac07fc36ad7411db19863d36de1b7e6898d71a Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sun, 5 Apr 2015 08:58:08 +0000 Subject: [PATCH] [SERVICES] - Free unknown groups when their reference count reaches zero CORE-9480 #resolve svn path=/trunk/; revision=67059 --- reactos/base/system/services/database.c | 3 +-- reactos/base/system/services/groupdb.c | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/reactos/base/system/services/database.c b/reactos/base/system/services/database.c index dbbaf0aadeb..98917d5e560 100644 --- a/reactos/base/system/services/database.c +++ b/reactos/base/system/services/database.c @@ -416,8 +416,7 @@ ScmDeleteServiceRecord(PSERVICE lpService) ScmDereferenceServiceImage(lpService->lpImage); /* Decrement the group reference counter */ - if (lpService->lpGroup) - lpService->lpGroup->dwRefCount--; + ScmSetServiceGroup(lpService, NULL); /* FIXME: SecurityDescriptor */ diff --git a/reactos/base/system/services/groupdb.c b/reactos/base/system/services/groupdb.c index 50db8d35ed0..b27185d867c 100644 --- a/reactos/base/system/services/groupdb.c +++ b/reactos/base/system/services/groupdb.c @@ -33,11 +33,26 @@ ScmSetServiceGroup(PSERVICE lpService, if (lpService->lpGroup != NULL) { - lpService->lpGroup->dwRefCount--; - - /* FIXME: What do we have to do when dwRefCount is 0? */ + ASSERT(lpService->lpGroup->dwRefCount != 0); + ASSERT(lpService->lpGroup->dwRefCount == (DWORD)-1 || + lpService->lpGroup->dwRefCount < 10000); + if (lpService->lpGroup->dwRefCount != (DWORD)-1) + { + lpService->lpGroup->dwRefCount--; + if (lpService->lpGroup->dwRefCount == 0) + { + ASSERT(lpService->lpGroup->TagCount == 0); + ASSERT(lpService->lpGroup->TagArray == NULL); + RemoveEntryList(&lpService->lpGroup->GroupListEntry); + HeapFree(GetProcessHeap(), 0, lpService->lpGroup); + lpService->lpGroup = NULL; + } + } } + if (lpGroupName == NULL) + return ERROR_SUCCESS; + GroupEntry = GroupListHead.Flink; while (GroupEntry != &GroupListHead) {