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
Bug in sympow #12858
Comments
comment:1
Needs an spkg. I'm sorry that I do not know enough about allocations to review this. Is there any way to doctest this, just out of curiosity? |
Author: Stephen Montgomery-Smith |
comment:3
I don't think this error only effects BSD. Rather I think it is an error that only happens very rarely, and I got unlucky. Also, I seem to have missed the message posted 10 months ago. What do you mean by "doctest"? |
comment:4
Sorry about that. "doctest" means that whenever we have a regression that we fix, we add a test to the suite of tests to check that it stays fixed. Is there a command that failed or leaked, or did Sage simply fail to compile this spkg? |
comment:5
OK, I did find this error with a doctest. I don't remember which doctest it was, but it was quite a few of them. But I think it depends on the computer you are using, OS, probably amount of RAM, other processes, etc. In my case it failed an existing doctest on one computer, and passed on other computers. But also, anyone who understands how malloc and free work should see instantly that the existing code has errors. See
|
comment:6
If you wouldn't mind terribly just undoing this patch and seeing which one it was, then we could add a nearly trivial patch adding a comment to that doctest saying
Since I don't really know C, I don't :) But presumably many other Sage developers do... |
comment:7
Replying to @kcrisman:
The problem here is that sympow is not even legal C. We had that conversation a while ago with David Kirkby that sympow was probably by far the worst piece of code in sage and it couldn't even be entered in "the obfuscated C contest" since some bits are not even legal C. The patch looks a bit weird but that's not any weirder than the surrounding code. And I actually understand the intent and by the look of it, it is the only case where TACKS[which] is not allocated. The other solution would be perform some check before deallocation. But further, TACKS is an array of pointers, shouldn't the pointer be NULL if not allocated or is it just at the discretion of the compiler, or possibly a compilation option? |
comment:8
My understanding is that arrays in C are not automatically initialized. |
comment:9
Replying to @sagetrac-stephen:
You are quite right. Wishful thinking of my part, although there must a gcc flag to do it. |
comment:10
Ping - if you happen to have time to check that out, I realize it could be annoying to do. |
comment:11
Adding keyword even though it may be a bug on all platforms, since it seems to have only been reported on FreeBSD. |
Changed keywords from sympow to sympow FreeBSD |
comment:16
this appears still to be the case, see https://gitlab.com/rezozer/forks/sympow/-/blob/master/disk.c#L60 |
Upstream: Not yet reported upstream; Will do shortly. |
comment:18
I think this was fixed by removing the https://gitlab.com/rezozer/forks/sympow/-/commit/f414d52ee601c54fab556ad2ecf79762ec7d5eef |
Reviewer: Dima Pasechnik |
comment:19
this "fix" replaces a wrong attempt to free memory held (a bit wrongly, as some pointers that by right should be NULL are not always, as found on this ticket) in an array of pointers by no freeing at all. This is of course fine if there are only created once during a run of the code, and this appears to be the case. |
Changed upstream from Not yet reported upstream; Will do shortly. to Fixed upstream, in a later stable release. |
comment:21
I've opened https://gitlab.com/rezozer/forks/sympow/-/issues/6 just so that the upstream is aware of this. |
In util.c there is a function free_data, which frees TACKS[0]. TACKS[0] is meant to be allocated in disk.c, but there are circumstances when TACKS[0] is not allocated.
The following patch seems to fix it. Notice that it makes use of the fact that free(NULL) should do nothing in the C programming language.
Upstream: Fixed upstream, in a later stable release.
CC: @orlitzky
Component: memleak
Keywords: sympow FreeBSD
Author: Stephen Montgomery-Smith
Reviewer: Dima Pasechnik
Issue created by migration from https://trac.sagemath.org/ticket/12858
The text was updated successfully, but these errors were encountered: