win-capture: Use stack buffer for small window titles
Avoids expensive malloc calls that might also contribute to excessive heap fragmentation.
This commit is contained in:
parent
ecf8c1239d
commit
d458780f02
@ -105,17 +105,29 @@ fail:
|
||||
|
||||
void get_window_title(struct dstr *name, HWND hwnd)
|
||||
{
|
||||
wchar_t *temp;
|
||||
int len;
|
||||
|
||||
len = GetWindowTextLengthW(hwnd);
|
||||
if (!len)
|
||||
return;
|
||||
|
||||
temp = malloc(sizeof(wchar_t) * (len + 1));
|
||||
if (GetWindowTextW(hwnd, temp, len + 1))
|
||||
dstr_from_wcs(name, temp);
|
||||
free(temp);
|
||||
if (len > 1024) {
|
||||
wchar_t *temp;
|
||||
|
||||
temp = malloc(sizeof(wchar_t) * (len + 1));
|
||||
if (!temp)
|
||||
return;
|
||||
|
||||
if (GetWindowTextW(hwnd, temp, len + 1))
|
||||
dstr_from_wcs(name, temp);
|
||||
|
||||
free(temp);
|
||||
} else {
|
||||
wchar_t temp[1024 + 1];
|
||||
|
||||
if (GetWindowTextW(hwnd, temp, len + 1))
|
||||
dstr_from_wcs(name, temp);
|
||||
}
|
||||
}
|
||||
|
||||
void get_window_class(struct dstr *class, HWND hwnd)
|
||||
|
Loading…
x
Reference in New Issue
Block a user