summary refs log tree commit diff stats
path: root/lib/system/exceptions.nim
diff options
context:
space:
mode:
authorȘtefan Talpalaru <stefantalpalaru@yahoo.com>2021-05-19 19:19:11 +0200
committerGitHub <noreply@github.com>2021-05-19 19:19:11 +0200
commita1c82c39af812b54cd3dd1e472c9088457fb7dc5 (patch)
treeaecc61e015df41e7a68d960e911d249e7fe141eb /lib/system/exceptions.nim
parent7052503ca8d360f11fabf476f7450dc3f794a602 (diff)
downloadNim-a1c82c39af812b54cd3dd1e472c9088457fb7dc5.tar.gz
asyncdispatch+stackTraceOverride: fix premature collection (#18039) [backport:1.2]
Copying StackTraceEntry instances when nimStackTraceOverride is defined
breaks the link between a cstring field that's supposed to point at
another string field in the same object.

Sometimes, the original object is garbage collected, that memory region
reused for storing other strings, so when the StackTraceEntry copy tries
to use its cstring pointer to construct a traceback message, it accesses
unrelated strings.

This only happens for async tracebacks and this patch prevents that by
making sure we only use the string fields when nimStackTraceOverride is
defined.

Async tracebacks also beautified slightly by getting rid of an extra line
that was supposed to be commented out, along with the corresponding debugging output.

There's also a micro-optimisation to avoid concatenating two strings just
to get their combined length.
Diffstat (limited to 'lib/system/exceptions.nim')
-rw-r--r--lib/system/exceptions.nim2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/system/exceptions.nim b/lib/system/exceptions.nim
index b5f4fc325..5dcd77bd0 100644
--- a/lib/system/exceptions.nim
+++ b/lib/system/exceptions.nim
@@ -29,7 +29,7 @@ type
       programCounter*: uint ## Program counter - will be used to get the rest of the info,
                             ## when `$` is called on this type. We can't use
                             ## "cuintptr_t" in here.
-      procnameStr*, filenameStr*: string ## GC-ed objects holding the cstrings in "procname" and "filename"
+      procnameStr*, filenameStr*: string ## GC-ed alternatives to "procname" and "filename"
 
   Exception* {.compilerproc, magic: "Exception".} = object of RootObj ## \
     ## Base exception class.