summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-02-03 09:48:52 +0100
committerAndreas Rumpf <rumpf_a@web.de>2017-02-03 09:48:52 +0100
commit04c4d3d77f86086efa2447c0c9b47ba84342d245 (patch)
tree420bc3040326613b2e10047b81da7d1a883ebb62
parent2c6c865b353d0e15783a95886d672288ca7da46c (diff)
downloadNim-04c4d3d77f86086efa2447c0c9b47ba84342d245.tar.gz
critical realloc bugfix; refs #4818
-rw-r--r--lib/system/alloc.nim7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim
index 6e7801be5..065b13460 100644
--- a/lib/system/alloc.nim
+++ b/lib/system/alloc.nim
@@ -295,10 +295,11 @@ proc writeFreeList(a: MemRegion) =
 proc requestOsChunks(a: var MemRegion, size: int): PBigChunk =
   when not defined(emscripten):
     if not a.blockChunkSizeIncrease:
-      if a.currMem < 64 * 1024:
+      let usedMem = a.currMem # - a.freeMem
+      if usedMem < 64 * 1024:
         a.nextChunkSize = PageSize*4
       else:
-        a.nextChunkSize = min(roundup(a.currMem shr 2, PageSize), a.nextChunkSize * 2)
+        a.nextChunkSize = min(roundup(usedMem shr 2, PageSize), a.nextChunkSize * 2)
   var size = size
 
   if size > a.nextChunkSize:
@@ -708,7 +709,7 @@ proc realloc(allocator: var MemRegion, p: pointer, newsize: Natural): pointer =
   if newsize > 0:
     result = alloc0(allocator, newsize)
     if p != nil:
-      copyMem(result, p, ptrSize(p))
+      copyMem(result, p, min(ptrSize(p), newsize))
       dealloc(allocator, p)
   elif p != nil:
     dealloc(allocator, p)
title='author Araq <rumpf_a@web.de> 2010-10-21 00:12:14 +0200 committer Araq <rumpf_a@web.de> 2010-10-21 00:12:14 +0200 version 0.8.10' href='/ahoang/Nim/commit/tests/accept/compile/tlexer.nim?h=devel&id=765366c1f377fbd9507e942385170b546d9d34d0'>765366c1f ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60