Click here to Skip to main content
15,881,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am compiling a host code using make command. The bellow errors showed up.

The sub code that caused this part of errors:

free(data_point);
    free(host_output);
    free(index_arr);
    free(array_dist);


Errors:

host/src/host.cpp:380:21: warning: attempt to free a non-heap object ‘data_point’ [-Wfree-nonheap-object]
     free(data_point);
                     ^
host/src/host.cpp:381:22: warning: attempt to free a non-heap object ‘host_output’ [-Wfree-nonheap-object]
     free(host_output);
                      ^
host/src/host.cpp:382:20: warning: attempt to free a non-heap object ‘index_arr’ [-Wfree-nonheap-object]
     free(index_arr);
                    ^
host/src/host.cpp:383:21: warning: attempt to free a non-heap object ‘array_dist’ [-Wfree-nonheap-object]
     free(array_dist);


What I have tried:

I tried to comment all the free and the errors are gone. But what I understand is that at the end of the host the memory should be freed up.
Posted
Updated 15-Sep-21 4:50am

1 solution

You should tidy up after yourself, yes - but you can only free object that you have allocated with malloc. You don't free items from the stack, which includes local and global variables, unless they contain a pointer to a heap object (i.e. one created by calling malloc)

That's what the error is telling you - these aren't on the heap, so they can't be freed.
Quite often, that means you've made a major boo-boo, such as returning a pointer to a local variable from a function instead of a heap allocation. I'd start by looking at what they do contain, and where you got it from!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900