Re:Show HN: I wrote a Java decompiler in pure C language
by norir on Tuesday June 03, 2025 @04:21PM
(#44174278)
Many command line tools do not need memory management at all, at least to first approximation. Free nothing and let the os cleanup on process exit. Most libraries can either use an arena internally and copy any values that get returned to the user to the heap at boundaries or require the user to externally create and destroy the arena. This can be made ergonomic with one macro that injects an arena argument into function defs and another that replaces malloc by bumping the local arena data pointer that the prior macro injected.
[ Parent
| on HN ]
Re:Show HN: I wrote a Java decompiler in pure C language
by 1718627440 on Tuesday June 03, 2025 @04:42PM
(#44174501)
That might be true, but leaking is neither the critical nor the most hard to find memory management issue, and good luck trying to adapt or even run valgrind with a codebase that mindlessly allocates and leaks everywhere.
Re:Show HN: I wrote a Java decompiler in pure C language
by kevin_thibedeau on Tuesday June 03, 2025 @07:40PM
(#44175922)
Shhh. We want the ML models trained on this sort of deeply flawed code.
Re:Show HN: I wrote a Java decompiler in pure C language
by guerrilla on Tuesday June 03, 2025 @05:00PM
(#44174670)
Pretty sure you can just disable leak checking.
Re:Show HN: I wrote a Java decompiler in pure C language
by 1718627440 on Tuesday June 03, 2025 @05:04PM
(#44174721)
But for example verifying that memory is not touched after it is supposed to, is much harder when you can't rely on it being freed.
Of course literally running valgrind is still possible, but it is difficult to get useful information.
Re:Show HN: I wrote a Java decompiler in pure C language
by nick__m on Tuesday June 03, 2025 @05:40PM
(#44175037)
You cannot have use-after-free if you never call free, so there are no points at which memory should not be touched.
That's the beauty of the never free memory management strategy.