malloc error when trying to assign the returned pointer to a struct field
rempas
rempas at tutanota.com
Sat Sep 9 08:21:38 UTC 2023
On Friday, 8 September 2023 at 19:14:47 UTC, H. S. Teoh wrote:
> The error message looks to me like a corruption of the malloc
> heap. These kinds of bugs are very hard to trace, because they
> may go undetected and only show up in specific circumstances,
> so small perturbations of completely unrelated code may make
> the bug appear or disappear -- just because the bug doesn't
> show up when you disable some code does not prove that that's
> where the problem is; it could be that corruption is still
> happening, it just so happens that it goes unnoticed when the
> behaviour of the code changes slightly.
Yep! That's what I guess as well! Tbh, I knew that playing with
memory and trying to write a system library will be a touch job
and I'm up for it! But these bugs really burn me out because like
you said, nobody can truly help because they are so weird...
> My guess is that you have a double-free somewhere, or there's a
> buffer overrun. Or maybe some bad interaction with the GC, e.g.
> if you tried to free a pointer from the GC heap. (Note that
> this may not immediately show up; free() could've assumed that
> everything was OK when it has in fact messed up its internal
> data structures; the problem would only show up later on in
> code that's actually unrelated to the real problem.)
I have commented out every `free` at this point just to be sure
and still the problem remains. I don't know what a "buffer
overrun" is, I will make my research and I will reply you when I
try. The GC does not exist as I'm `betterC`.
> If I were in your shoes I'd use Valgrind / Memcheck to try to
> find the real cause of the problem. Chances are, it may have
> nothing to do with the bit of code you quoted at all. You
> could try to insert extra malloc/free's in various places
> around the code (in places along the code path, but unrelated
> to the problematic code) to see if that changes the behaviour
> of the bug. If it does, your corruption is likely somewhere
> other than the _ptr code you showed.
>
>
> T
Thanks for the advice! I already used Valgrind before I bother
you guys but because at this point of development, I didn't cared
about freeing the memory, "valgrind" points so many errors that
it isn't useful to help me identify what's wrong.
More information about the Digitalmars-d-learn
mailing list