Hang with 100% CPU when closing service handle twice in a row
Hi,first of all, I'm not quite sure if this is the right place to report a possible 2008 bug.I know that I should use the "How to share feedback" icon on the desktop, butI deleted this icon accidentally. If this is not the right place to report a bug, I'd begrateful for a hint where to go instead.Ok, now, that's what happens:One of my applications, which job is to manage specific services, hanged afterlisting the services, eating up 100% CPU. Debugging turned up a bug in myapplication, which resulted in calling CloseServiceHandle twice in a row on thesame service handle. The second call to CloseServiceHandle hangs.Doing the same on Vista or XP results in a more expected return value of FALSEwith GetLastError returning ERROR_INVALID_HANDLE.So, while this is certainly a problem in my application, I think this is also a bug in2008, isn't it?Below you find a self-contained testcase, which allows to reproduce the problem.It prints ret 1: TRUE lasterr: 0 ret 2: FALSE lasterr: 6on XP or Vista. On 2008, it just prints ret 1: TRUE lasterr: 0and than hangs using all CPU it can grab. Code Block#include <alloca.h>#include <stdio.h>#include <windows.h>#include <winsvc.h>intmain (){ SC_HANDLE sm = (SC_HANDLE) 0; SC_HANDLE sh = (SC_HANDLE) 0; SERVICE_STATUS ss; LPENUM_SERVICE_STATUS srv_buf; LPQUERY_SERVICE_CONFIG qsc_buf; DWORD num_services, resume_handle = 0; DWORD bytes_needed = 32768; BOOL ret; srv_buf = (LPENUM_SERVICE_STATUS) alloca (bytes_needed); qsc_buf = (LPQUERY_SERVICE_CONFIG) alloca (8192); if (!(sm = OpenSCManager (NULL, NULL, SC_MANAGER_CONNECT | SC_MANAGER_ENUMERATE_SERVICE))) return 0; if (!EnumServicesStatus (sm, SERVICE_WIN32, SERVICE_STATE_ALL, srv_buf, bytes_needed, &bytes_needed, &num_services, &resume_handle)) return 0; if (!(sh = OpenService (sm, srv_buf[0].lpServiceName, GENERIC_READ))) return 0; ret = CloseServiceHandle (sh); printf ("ret 1: %s lasterr: %lu\n", ret ? "TRUE" : "FALSE", GetLastError ()); /* Erroneous second call to CloseServiceHandle, hangs on 2008 RC1. */ ret = CloseServiceHandle (sh); printf ("ret 2: %s lasterr: %lu\n", ret ? "TRUE" : "FALSE", GetLastError ()); return 0;}Corinna
December 18th, 2007 8:44pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics