services: Add a grab_service function.

Sebastian Lackner sebastian at fds-team.de
Wed Aug 17 02:12:27 CDT 2016


Signed-off-by: Sebastian Lackner <sebastian at fds-team.de>
---
 programs/services/rpc.c      |    4 +---
 programs/services/services.c |   13 +++++++++----
 programs/services/services.h |    1 +
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/programs/services/rpc.c b/programs/services/rpc.c
index 45366fb9..eb8f4ff 100644
--- a/programs/services/rpc.c
+++ b/programs/services/rpc.c
@@ -373,9 +373,7 @@ DWORD __cdecl svcctl_OpenServiceW(
         return ERROR_INVALID_NAME;
 
     scmdatabase_lock(manager->db);
-    entry = scmdatabase_find_service(manager->db, lpServiceName);
-    if (entry != NULL)
-        InterlockedIncrement(&entry->ref_count);
+    entry = grab_service(scmdatabase_find_service(manager->db, lpServiceName));
     scmdatabase_unlock(manager->db);
 
     if (entry == NULL)
diff --git a/programs/services/services.c b/programs/services/services.c
index f7a2725..9be9bb8 100644
--- a/programs/services/services.c
+++ b/programs/services/services.c
@@ -346,15 +346,13 @@ static void scmdatabase_autostart_services(struct scmdatabase *db)
                     break;
                 services_list = slist_new;
             }
-            services_list[i] = service;
-            InterlockedIncrement(&service->ref_count);
-            i++;
+            services_list[i++] = grab_service(service);
         }
     }
+    size = i;
 
     scmdatabase_unlock(db);
 
-    size = i;
     for (i = 0; i < size; i++)
     {
         DWORD err;
@@ -494,6 +492,13 @@ void release_process(struct process_entry *process)
     scmdatabase_unlock(db);
 }
 
+struct service_entry *grab_service(struct service_entry *service)
+{
+    if (service)
+        InterlockedIncrement(&service->ref_count);
+    return service;
+}
+
 void release_service(struct service_entry *service)
 {
     struct scmdatabase *db = service->db;
diff --git a/programs/services/services.h b/programs/services/services.h
index 16f99f89..59d8d00 100644
--- a/programs/services/services.h
+++ b/programs/services/services.h
@@ -84,6 +84,7 @@ BOOL validate_service_name(LPCWSTR name);
 BOOL validate_service_config(struct service_entry *entry);
 DWORD save_service_config(struct service_entry *entry);
 void free_service_entry(struct service_entry *entry);
+struct service_entry *grab_service(struct service_entry *service);
 void release_service(struct service_entry *service);
 void service_lock(struct service_entry *service);
 void service_unlock(struct service_entry *service);
-- 
2.9.0



More information about the wine-patches mailing list