Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vala in self-hosted mode (i.e. running mal) has rare memory corruption (probably in throw/try/catch) #663

Open
kanaka opened this issue Aug 21, 2024 · 1 comment

Comments

@kanaka
Copy link
Owner

kanaka commented Aug 21, 2024

I was seeing this issue in step9 tests and simplified it down to the following test file (vala-memory-corruption.mal):

(try* (nth () 1) (catch* e (prn "e:" e)))
(try* (list 1) (catch* e (prn "e:" e)))
(try* (throw "e") (catch* e (do (prn "e:" e) 7)))
(try* (do (try* "t1" (catch* e "c1")) (throw "e1")) (catch* e "c2"))
(try* (try* (throw "e1") (catch* e (throw "e2"))) (catch* e "c2"))
(try* (map throw (list "my err")) (catch* e e))
(try* (eval (read-string "(+ 1")) (catch* e (prn :e e)))

;; This fails
(map (fn* (x) (list? x)) (list 1 2 3))
;=>(false false false)

Note that it is very sensitive to exactly the content above. If you duplicate or remove any of the try/catch or modify them in any significant way then the problem in the last test goes away (fairly strong indication of memory corruption).

Run the test above in self-hosted mode (vala stepA running mal step9) like this:

$ docker run -it --rm -u $(id -u) -v $(pwd):/mal -w /mal/impls/vala -e STEP=step9_try -e MAL_IMPL=vala ghcr.io/kanaka/mal-test-vala:20200211_055016-g8a19f603 ../../runtest.py ../../vala-memory-corruption.mal -- ../mal/run
TEST: '(try* (nth () 1) (catch* e (prn "e:" e)))' -> ['',] -> SUCCESS (result ignored)
...
TEST: '(map (fn* (x) (list? x)) (list 1 2 3))' -> ['',(false false false)] -> FAIL (line 11):
    Expected : '.*\n\\(false\\ false\\ false\\)'
    Got      : "(map (fn* (x) (list? x)) (list 1 2 3))\nUncaught exception: 'ast' not found \n  in mal EVAL: (map (fn* (x) (list? x)) (list 1 2 3))"

@sgtatham Since you contributed the vala implementation, any chance you want to take a look at this? If it's not immediately obvious, I would probably try and leverage valgrind (unless vala has a more bespoke memory leak debug program).

@sgtatham
Copy link
Contributor

I'm sorry to say that I haven't touched Vala since then! I wrote a Vala implementation of mal because it seemed like a good way to learn the language in the first place, which I wanted to do in order to work on an existing program written in it. But then I gave up on the thing I wanted to do to that program. In order to debug this, I'd have to relearn a lot of stuff from scratch.

I agree valgrind or ASan is probably a good place to start, because Vala compiles down to C using the GLib APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants