Skip to content

Commit

Permalink
Add NULL checks to CloseHandle in BudgetUpdateTaskDXGI
Browse files Browse the repository at this point in the history
  • Loading branch information
bbernhar committed Feb 12, 2024
1 parent 667edf4 commit efbbc5e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/gpgmm/d3d12/BudgetUpdateDXGI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace gpgmm::d3d12 {

BudgetUpdateTaskDXGI::BudgetUpdateTaskDXGI(ResidencyManagerDXGI* const residencyManager)
BudgetUpdateTaskDXGI::BudgetUpdateTaskDXGI(ResidencyManagerDXGI* residencyManager)
: mResidencyManager(residencyManager),
mBudgetNotificationUpdateEvent(CreateEventW(NULL, FALSE, FALSE, NULL)),
mUnregisterAndExitEvent(CreateEventW(NULL, FALSE, FALSE, NULL)) {
Expand All @@ -32,8 +32,12 @@ namespace gpgmm::d3d12 {
}

BudgetUpdateTaskDXGI::~BudgetUpdateTaskDXGI() {
CloseHandle(mUnregisterAndExitEvent);
CloseHandle(mBudgetNotificationUpdateEvent);
if (mUnregisterAndExitEvent != nullptr) {
::CloseHandle(mUnregisterAndExitEvent);
}
if (mBudgetNotificationUpdateEvent != nullptr) {
::CloseHandle(mBudgetNotificationUpdateEvent);
}
}

MaybeError BudgetUpdateTaskDXGI::operator()() {
Expand All @@ -52,9 +56,6 @@ namespace gpgmm::d3d12 {
if (FAILED(hr)) {
break;
}

DebugLog(MessageId::kBudgetUpdated, mResidencyManager)
<< "Updated budget from OS notification.";
break;
}
// mUnregisterAndExitEvent
Expand All @@ -70,7 +71,7 @@ namespace gpgmm::d3d12 {
}

if (FAILED(hr)) {
ErrorLog(ErrorCode::kBudgetInvalid, mResidencyManager)
ErrorLog(ErrorCode::kBudgetInvalid, mResidencyManager.Get())
<< "Unable to update budget: " +
GetErrorResultMessage(hr, mResidencyManager->GetDevice());
}
Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/BudgetUpdateDXGI.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ namespace gpgmm::d3d12 {
BudgetUpdateTaskDXGI(ResidencyManagerDXGI* const residencyManager);
~BudgetUpdateTaskDXGI() override;

private:
// VoidCallback interface
MaybeError operator()() override;

// BudgetUpdateTask interface
bool UnregisterAndExit() override;

private:
ResidencyManagerDXGI* const mResidencyManager;

HANDLE mBudgetNotificationUpdateEvent = INVALID_HANDLE_VALUE;
Expand Down

0 comments on commit efbbc5e

Please sign in to comment.