How do I debug this "invalid memory reference"?

174 views
Skip to first unread message

Sage Gerard

unread,
Jun 2, 2021, 10:22:10 AM6/2/21
to Racket Users

Hi all,

Consider this small FFI that currently works only on GNU/Linux.

https://github.com/zyrolasting/xiden/blob/libcrypto/crypto.rkt
https://github.com/zyrolasting/xiden/blob/libcrypto/crypto/crypto.c

`raco test` intermittently fails this module with "invalid memory reference.  Some debugging context lost". I can silence the error by commenting out all use of `valid?` in the tests (starts on line 413), which allows me to blame one of the verification functions. However, I do not understand the nature of the problem well enough to know where exactly the problem occurred, or what to do when I find it.

My current guess is that I passed a pointer to GC-managed memory, and the pointer referenced an old location.

Besides continuing to throw prints around, how should I go about debugging this?

--
~slg

Sage Gerard

unread,
Jun 2, 2021, 10:45:23 AM6/2/21
to Racket Users

Credit to @samth on the Discord for noticing that I did not use `_bytes/nul-terminated` on Racket CS byte strings. Doing so fixed the issue. Thanks, Sam!

--
~slg
Reply all
Reply to author
Forward
0 new messages