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
Memory leak - i would recommend having better memory management in the program. #20
Comments
This seems like a good idea. Besides the input field |
That would be even greater! Do remember to include in your documentation, perhaps in your readme on how to use your calculator. 😄 |
I was playing around with it a little bit and I am pretty sure most of those allocs come from ncurses |
We still have to free them, I'm sure it's in the ncurses documentation somewhere :) Having a We also don't free the |
If you use |
I wrote a very small program that basically does the same thing that pcalc but it also suffers from those memory leaks. I have to admit that I dont have much experience with ncurses and the documentation (https://invisible-island.net/ncurses/ncurses-intro.html#updating) doesnt really help either. Even the example has the same memory leaks. Very small program I wrote
valgrind --leak-check=full ./output/main
|
Weird... I might have to look into this tomorrow. |
Yes I tried but this just adds one free to the total counter and nothing else. |
Ah i think i have found the solution.
So, basically i think its alright that ncurses "leaks" memory because it is if it would be used for the next instance when calling Though, as @alt-romes mentions, there are some teardown of structures to be done 😉 |
Thanks for the information. |
I think we sould fix this really soon. I will try to fix it as soon as possible but I also could need some help. |
Hello! Can someone do a valgrind check for me please - so that I can close the issue? Thank you, |
I have experienced a problem but this problem only occurs after couple hundred inputs. IMPORTANT: I already have a fix. #30 I looked into the code and think the problem is in this function. The realloc returns the pointer to s->elements which is a long long pointer and not a numberstack pointer or am I wrong here.
valgrind --leak-check=full -s ./pcalc
DevManu-de |
The problem is not due to it not being a numberstack - the realloc is to resize the list of elements (of type long long) However, I just noticed the realloc is a false return as you just said in your PR. Thank you |
The calculator might not be a big program but there is some memory leaks. As seen above, when starting through
Valgrind
, it shows, when the program has been stopped byCTRL-C
that there is memory leakage. I see that in yournumberstack.c
you usemalloc()
.The amount of allocations at initialization is 190, whereas quitting instantly only causes 12 frees.
Perhaps i would recommend that you create a teardown function that tearsdown all your allocated structures.
As well that this teardown functionality occurs by some character that is used in the input pane in the program.
In short;
q
orQ
in input field (Quit the calculator)Maybe this is not your intention with the program but its a good practice to make as low of a memory leakage as possible.
The text was updated successfully, but these errors were encountered: