other-licenses/7zstub/src/Windows/Handle.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 // Windows/Handle.h
michael@0 2
michael@0 3 #ifndef __WINDOWS_HANDLE_H
michael@0 4 #define __WINDOWS_HANDLE_H
michael@0 5
michael@0 6 namespace NWindows {
michael@0 7
michael@0 8 class CHandle
michael@0 9 {
michael@0 10 protected:
michael@0 11 HANDLE _handle;
michael@0 12 public:
michael@0 13 operator HANDLE() { return _handle; }
michael@0 14 CHandle(): _handle(NULL) {}
michael@0 15 ~CHandle() { Close(); }
michael@0 16 bool Close()
michael@0 17 {
michael@0 18 if (_handle == NULL)
michael@0 19 return true;
michael@0 20 if (!::CloseHandle(_handle))
michael@0 21 return false;
michael@0 22 _handle = NULL;
michael@0 23 return true;
michael@0 24 }
michael@0 25 void Attach(HANDLE handle)
michael@0 26 { _handle = handle; }
michael@0 27 HANDLE Detach()
michael@0 28 {
michael@0 29 HANDLE handle = _handle;
michael@0 30 _handle = NULL;
michael@0 31 return handle;
michael@0 32 }
michael@0 33 };
michael@0 34
michael@0 35 }
michael@0 36
michael@0 37 #endif

mercurial