summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Brainman <alex.brainman@gmail.com>2010-11-24 11:47:35 +1100
committerAlex Brainman <alex.brainman@gmail.com>2010-11-24 11:47:35 +1100
commitced950d58a7267e0ad517a7b514825711f8a6e47 (patch)
tree84898ee401aa536a3e8d18842d9cefdf4f314841 /src
parent43f3ce59d36047ccb9160d698a0fbbded19cc568 (diff)
downloadgo-ced950d58a7267e0ad517a7b514825711f8a6e47.tar.gz
runtime: fix SysFree to really free memory on Windows
Fixes issue 1294. R=golang-dev, PeterGo, iant CC=golang-dev http://codereview.appspot.com/3271041
Diffstat (limited to 'src')
-rw-r--r--src/pkg/runtime/windows/mem.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/src/pkg/runtime/windows/mem.c b/src/pkg/runtime/windows/mem.c
index 0b5d56c8b..c113c40c3 100644
--- a/src/pkg/runtime/windows/mem.c
+++ b/src/pkg/runtime/windows/mem.c
@@ -15,10 +15,25 @@ enum {
PAGE_EXECUTE_READWRITE = 0x40,
};
+static void
+abort(int8 *name)
+{
+ uintptr errno;
+
+ errno = (uintptr)runtime·stdcall(runtime·GetLastError, 0);
+ runtime·printf("%s failed with errno=%d\n", name, errno);
+ runtime·throw(name);
+}
+
void*
runtime·SysAlloc(uintptr n)
{
- return runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+ void *v;
+
+ v = runtime·stdcall(runtime·VirtualAlloc, 4, nil, n, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+ if(v == 0)
+ abort("VirtualAlloc");
+ return v;
}
void
@@ -31,7 +46,11 @@ runtime·SysUnused(void *v, uintptr n)
void
runtime·SysFree(void *v, uintptr n)
{
- runtime·stdcall(runtime·VirtualFree, 3, v, n, MEM_RELEASE);
+ uintptr r;
+
+ r = (uintptr)runtime·stdcall(runtime·VirtualFree, 3, v, 0, MEM_RELEASE);
+ if(r == 0)
+ abort("VirtualFree");
}
void