Never leak process handles or DirectX textures again using RAII with custom deleters:
struct HandleDeleter {
void operator()(HANDLE h) const {
if (h && h != INVALID_HANDLE_VALUE) CloseHandle(h);
}
};
using UniqueHandle = std::unique_ptr<void, HandleDeleter>;
// Usage:
UniqueHandle hProcess(OpenProcess(PROCESS_VM_READ, FALSE, pid));
// Handle automatically closes on function return or exception!