Skip to content

Commit

Permalink
Fix some memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Jun 17, 2022
1 parent 2fd6849 commit 57e36eb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"args": [
"/Zi", // debug only
"/EHsc", // debug only
"/MTd", // debug only
"/D", "CHROMABROWSE_DEBUG", // debug only
"/nologo",
"/W4",
Expand Down
2 changes: 2 additions & 0 deletions src/FolderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void FolderWindow::onCreate() {
view = nullptr;
// destroy and recreate browser
browser->Destroy();
browser = nullptr;
if (!initBrowser())
return;
// don't set property bag! (breaks sorting)
Expand Down Expand Up @@ -242,6 +243,7 @@ void FolderWindow::resultsFolderFallback() {
CComPtr<IShellItem> childItem;
while (enumItems->Next(1, &childItem, nullptr) == S_OK) {
results->AddItem(childItem);
childItem = nullptr;
}
// for some reason changing the sort columns immediately after adding items
// breaks the folder view, so delay it until the browser has had a chance to
Expand Down
4 changes: 4 additions & 0 deletions src/PreviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ void PreviewWindow::init() {
RegisterClass(&containerClass);
}

void PreviewWindow::uninit() {
previewFactoryCache.clear();
}

PreviewWindow::PreviewWindow(CComPtr<ItemWindow> parent, CComPtr<IShellItem> item, CLSID previewID)
: ItemWindow(parent, item)
, previewID(previewID)
Expand Down
1 change: 1 addition & 0 deletions src/PreviewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace chromabrowse {
class PreviewWindow : public ItemWindow, public IPreviewHandlerFrame {
public:
static void init();
static void uninit();

PreviewWindow(CComPtr<ItemWindow> parent, CComPtr<IShellItem> item, CLSID previewID);

Expand Down
10 changes: 7 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int showCommand) {
updateJumpList(nullptr);

chromabrowse::ItemWindow::uninit();
chromabrowse::PreviewWindow::uninit();
OleUninitialize();
return 0;
}
Expand Down Expand Up @@ -137,12 +138,14 @@ DWORD WINAPI updateJumpList(void *) {
if (FAILED(favoritesFolder->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&enumItems))))
return false;

CComPtr<IShellItem> childItem;
if (IsWindows10OrGreater()) {
// TODO: hack!! the first 20 items in Quick Access are recents
for (int i = 0; i < 20; i++)
enumItems->Next(1, &childItem, nullptr);
for (int i = 0; i < 20; i++) {
CComPtr<IShellItem> tempItem;
enumItems->Next(1, &tempItem, nullptr);
}
}
CComPtr<IShellItem> childItem;
while (enumItems->Next(1, &childItem, nullptr) == S_OK) {
CComHeapPtr<wchar_t> displayName, parsingName;
childItem->GetDisplayName(SIGDN_NORMALDISPLAY, &displayName);
Expand Down Expand Up @@ -174,6 +177,7 @@ DWORD WINAPI updateJumpList(void *) {
link->SetIconLocation(iconFile, index);
}
}
childItem = nullptr; // CComPtr isn't very smart
}

if (FAILED(jumpList->AddUserTasks(tasks))) {
Expand Down

0 comments on commit 57e36eb

Please sign in to comment.