From 8f07e6932b23acf5a3233dc55bbe7a426f35fc28 Mon Sep 17 00:00:00 2001 From: Rob Shearman Date: Tue, 24 Mar 2009 11:25:35 +0000 Subject: [PATCH] services: Add a ref count to the service entry in svcctl_CreateServiceW. The ref count will be released by SC_RPC_HANDLE_destroy when the returned handle is destroyed. Change svcctl_OpenServiceW to use InterlockedIncrement to increment the ref count since the service is in the database and therefore could be shared and SC_RPC_HANDLE_destroy doesn't take the scmdatabase lock when decrementing the ref count. --- programs/services/rpc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/programs/services/rpc.c b/programs/services/rpc.c index 7c09f55cc8b..22391c24ec2 100644 --- a/programs/services/rpc.c +++ b/programs/services/rpc.c @@ -309,7 +309,7 @@ DWORD svcctl_OpenServiceW( scmdatabase_lock_shared(manager->db); entry = scmdatabase_find_service(manager->db, lpServiceName); if (entry != NULL) - entry->ref_count++; + InterlockedIncrement(&entry->ref_count); scmdatabase_unlock(manager->db); if (entry == NULL) @@ -358,6 +358,7 @@ DWORD svcctl_CreateServiceW( err = service_create(lpServiceName, &entry); if (err != ERROR_SUCCESS) return err; + entry->ref_count = 1; entry->config.dwServiceType = entry->status.dwServiceType = dwServiceType; entry->config.dwStartType = dwStartType; entry->config.dwErrorControl = dwErrorControl;