<div dir="ltr">Hi<br>Could someone take out a little time to review the code once?<br>Bug I intend to solve: <a href="https://bugs.winehq.org/show_bug.cgi?id=39640">https://bugs.winehq.org/show_bug.cgi?id=39640</a><br><br><div>I am new to wine. So, I would appreciate suggestions regarding my coding style if that's not-so-perfect according to wine standards. Or any other problems with the code I have written. I apologize for submitting an untested code earlier. I hope now it works fine.<br><br><br>/*-------------------------------------------CODE--------------------------------------------------*/<br>typedef struct process_list {<br>    DWORD        *pid;       /*dynamic array to store the process IDs*/<br>    SIZE_T      count;      /*index to maintain the last entry of the array;*/<br>    SIZE_T      size;       /*the current size of the pid array*/<br>} process_list;<br><br>static void init_process_list(process_list *list) {<br>    list->size = 4;            /*initialise size with 4. Will increase if necessary.*/<br>    list->pid = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, list->size * sizeof(list->pid));<br>    list->count = 0;<br>}<br><br>static void increase_list_size(process_list *list) {<br>    list->size *= 2;<br>    list->pid = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, list->pid, list->size * sizeof(list->pid));<div><b>//DOUBT: </b>Would sizeof(list->pid) be better or sizeof(int)? <br>//Since in the former case,<font face="arial, helvetica, sans-serif"> <span style="color:rgb(0,0,0);font-size:13px;white-space:pre-wrap">since list->pid is actually a pointer to DWORD, so //sizeof(list->pid) would return 8 bytes and not 4 bytes.</span></font></div><div><br></div><div>}<br><br>static void process_list_append(process_list *list, DWORD id) {<br>    if(list->count == list->size)<br>        increase_list_size(list);<br>    list->pid[list->count] = id;<br>    list->count += 1;<br>}<br><br>static void free_process_list(process_list *list) {<br>    HeapFree(GetProcessHeap(), 0, list->pid);<br>}<br><br><br>static void enum_process_children(HANDLE snapshot, process_list *list, DWORD pid) {<br>    PROCESSENTRY32 entry;<br><br>    SIZE_T start, end, i ;<br><br>    start = list->count;<br><br>    entry.dwSize = sizeof(entry);<br><br>    if(!Process32First(snapshot, &entry))<br>        return;<br><br>    do<br>    {  <br>        if(entry.th32ParentProcessID == pid)<br>            process_list_append(list, entry.th32ProcessID);<br>    } while (Process32Next(snapshot, &entry));<br><br>    end = list->count;<br><br>    for(i = start; i < end; ++i)<br>    {<br>        enum_process_children(snapshot, list, list->pid[i]);<br>    }<br>}<br><br><br>void ProcessPage_OnEndProcessTree(void)<br>{<br>   {...}<br>    process_list      list;<br>    SIZE_T             i;<br>    HANDLE           snapshot;<br>    <br>    {...}<br>    <br>    init_process_list(&list);<br><br>    if(list.pid == NULL)<br>        return;<br><br>    process_list_append(&list, dwProcessId);<br><br>    snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br><br>    if(!snapshot)<br>        return;<br><br>    enum_process_children(snapshot, &list, dwProcessId);<br>   <br>    CloseHandle(snapshot);<br><br>    for(i = 0; i < list.count; ++i) {<br>        hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, list.pid[i]);        <br><br>        if (!hProcess)<br>        {<br>            GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));<br>            MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);<br>            break;<br>        }<br><br>        if (!TerminateProcess(hProcess, 0))<br>        {<br>            GetLastErrorText(wstrErrorText, sizeof(wstrErrorText)/sizeof(WCHAR));<br>            MessageBoxW(hMainWnd, wstrErrorText,wszUnable2Terminate, MB_OK|MB_ICONSTOP);<br>        }<br>        CloseHandle(hProcess);<br>    }<br><br>    free_process_list(&list);<br>}<div><br></div><div><br></div><div>/*---------------------------------------END OF CODE------------------------------------------*/<br><br>Thanks and regards<br>--<br>Akarsha Sehwag</div></div></div></div>