[pidgin-musictracker] r470 committed - Don't leak handles to the winamp process...

2 views
Skip to first unread message

pidgin-mu...@googlecode.com

unread,
Sep 19, 2010, 12:47:43 PM9/19/10
to pidgin-musict...@googlegroups.com
Revision: 470
Author: jon.t...@dronecode.org.uk
Date: Sun Sep 19 09:47:14 2010
Log: Don't leak handles to the winamp process
Don't leak memory we allocate inside the winamp process


http://code.google.com/p/pidgin-musictracker/source/detail?r=470

Modified:
/trunk/src/winamp.c

=======================================
--- /trunk/src/winamp.c Mon Mar 1 11:47:29 2010
+++ /trunk/src/winamp.c Sun Sep 19 09:47:14 2010
@@ -11,6 +11,12 @@
{
// Allocate memory inside Winamp's address space to exchange data with it
char *winamp_info = VirtualAllocEx(hProcess, NULL, 4096, MEM_COMMIT,
PAGE_READWRITE);
+ if (!winamp_info)
+ {
+ trace("VirtualAllocEx in winamp process failed");
+ return FALSE;
+ }
+
wchar_t *winamp_filename = (wchar_t*)(winamp_info+1024);
wchar_t *winamp_key = (wchar_t*)(winamp_info+2048);
wchar_t *winamp_value = (wchar_t*)(winamp_info+3072);
@@ -35,6 +41,8 @@
WideCharToMultiByte(CP_UTF8, 0, wdest, -1, dest, STRLEN, NULL,
NULL);
trace("Got info '%s', return value %d", dest, rc);

+ VirtualFreeEx(hProcess, winamp_info, 0, MEM_RELEASE);
+
return (rc != 1);
}

@@ -43,6 +51,12 @@
{
// Allocate memory inside Winamp's address space to exchange data
with it
char *winamp_info = VirtualAllocEx(hProcess, NULL, 4096,
MEM_COMMIT, PAGE_READWRITE);
+ if (!winamp_info)
+ {
+ trace("VirtualAllocEx in winamp process failed");
+ return FALSE;
+ }
+
char *winamp_filename = (char*)(winamp_info+1024);
char *winamp_key = (char*)(winamp_info+2048);
char *winamp_value = (char*)(winamp_info+3072);
@@ -65,6 +79,8 @@

trace("Got info for key '%s' is '%s', return value %d", key, dest,
rc);

+ VirtualFreeEx(hProcess, winamp_info, 0, MEM_RELEASE);
+
return (rc != 1);
}

@@ -84,6 +100,10 @@
DWORD processId;
GetWindowThreadProcessId(hWnd, &processId);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, processId);
+ if (!hProcess)
+ {
+ trace("Failed to open winamp process");
+ }

int playing = SendMessage(hWnd, WM_WA_IPC, 1, IPC_ISPLAYING);
if (playing == 0)
@@ -142,4 +162,6 @@
pcre_free(re);
free(title);
}
-}
+
+ CloseHandle(hProcess);
+}

Reply all
Reply to author
Forward
0 new messages