Index: sandbox/win/src/win_utils.cc |
diff --git a/sandbox/win/src/win_utils.cc b/sandbox/win/src/win_utils.cc |
index 34a966ac80e0e39fca9828dc00f58c6e7aee6b6c..12f818926b4bdb642efc658644b6b9e75ca19e22 100644 |
--- a/sandbox/win/src/win_utils.cc |
+++ b/sandbox/win/src/win_utils.cc |
@@ -243,21 +243,22 @@ |
NtQueryObjectFunction NtQueryObject = NULL; |
ResolveNTFunctionPtr("NtQueryObject", &NtQueryObject); |
- OBJECT_NAME_INFORMATION* name = NULL; |
- ULONG size = 0; |
+ OBJECT_NAME_INFORMATION initial_buffer; |
+ OBJECT_NAME_INFORMATION* name = &initial_buffer; |
+ ULONG size = sizeof(initial_buffer); |
// Query the name information a first time to get the size of the name. |
NTSTATUS status = NtQueryObject(handle, ObjectNameInformation, name, size, |
&size); |
- if (!size) |
- return false; |
- |
- scoped_ptr<BYTE[]> name_ptr(new BYTE[size]); |
- name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(name_ptr.get()); |
- |
- // Query the name information a second time to get the name of the |
- // object referenced by the handle. |
- status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); |
+ scoped_ptr<OBJECT_NAME_INFORMATION> name_ptr; |
+ if (size) { |
+ name = reinterpret_cast<OBJECT_NAME_INFORMATION*>(new BYTE[size]); |
+ name_ptr.reset(name); |
+ |
+ // Query the name information a second time to get the name of the |
+ // object referenced by the handle. |
+ status = NtQueryObject(handle, ObjectNameInformation, name, size, &size); |
+ } |
if (STATUS_SUCCESS != status) |
return false; |