-
Notifications
You must be signed in to change notification settings - Fork 361
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
Make sure create_table sets allocation mode #5953
Conversation
I noticed that gmtmath were unable to free datasets it had allocated because the tables never had their alloc_mode set to GMT_ALLOC_INTERNALLY.
Sorry, approved before noticing the CI issues - looks like there may be some problems here. Edit: many tests fail locally too. |
Yep, working on it. |
Problem is this: While we set the alloc_mode for a dataset we create in GMT to GMT_ALLOC_INTERNALLY, we failed to set the alloc_mode for its tables to that, so it defaulted to GMT_ALLOC_EXTERNALLY [0]. Hence, a bunch of tables created in gmtmath did not get freed and resulted in a memory leak (only seen if compiling with -DMEMDEBUG). This PR tries to fix this by setting the correct alloc_mode, but this opened up another issue that had been hidden due to the first bugs: The current example (there may be more) is when pscoast creates a dataset from DCW and then passes that to psxy for plotting. The dataset and tables are now properly alloc_mode'd but since it was created at the same allocation level as psxy (2), the psxy module destroys the data upon completion. This is not known in pscoast that also tries to free it and by that time there is junk in that memory, causing other crashes. The general problem seems to be this:
Module 3 operates at level 2 and hence seems nothing wrong in destroying memory allocated at that level. |
This PR grew a bit because there were several pretty bad situations in the API related mostly to GMT modules passing GMT_DATASET structures via GMT_IS_REFERENCE to other module, so I do not think this should have any effect on the externals, but we will leave it as WIP until @meghanrjones @seisman @weiji14 @joa-quim have tried this branch and given green light. Here is the main things in this PR:
A few comments were also added. This should strengthen the API for dataset virtual use. Please give it a spin asap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No visible effects on Julia
I got a crash on Edit: triggered tests at GenericMappingTools/pygmt@388d3a2 using Will see if I can find any other problems using Edit2: |
I am unable to test the PyGMT until Tuesday since conda does not yet support M1 natively. If you can see what is happening in debug please let me know. |
Yes, just double-checked:
|
Sounds good, I'll take a look. |
I ssh'ed into macnut (Intel) and ran the tests there too and no errors. Please cd into your build/src directory and run testapi_uservectors -q Does it crash? |
Yes:
Even more bizarre - when I run |
If you run this in Xcode you can under Diagnostic tab select Malloc guard, malloc etc (3 separate things I think) and then it will find the first violation instead of the above error. |
I do get lots of warnings on this one but no crash, so I will look at that here. |
Thanks. I am working on a change to address numerous meg issues related to segments. I had a single alloc_mode variable for a segment, but when externals provide columns it is possible that only some are provided externally and others are allocated in GMT. So the segment alloc_mode must be a vector as well and we must set the mode for each data pointer to INTERNAL or EXTERNAL so that freeing can work. Still testing now after many changes. |
Since GMT_Put_Vector adds individual vectors we really need to track allocation mode accordingly.
Updated with per-column allocation mode. Test again pass for me and a lot less memory issues in the logs. If you have not seen these before you will need to set MEM_DEBUG in the Advanced.cmake settings and then you will see things like
I have a few of these I am still tracking down but the majority of the ones associated with testapi_uservectors are gone. |
Down to three failing tests:
Here's an example simplified to one line that fails for me:
I think all three failures relate to the grdview -T option: Lines 1300 to 1326 in fd54c73
|
Are you sure you are on the latest commit? gmt_get_segment takes two arguments now. |
Fix bad grdview usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problems with the gmt and pygmt (both on main and gmt-in) tests for me after the latest update to grdview.
OK, I still have a few memory leaks but all tests pass for me etc. I can continue to work on this but it does not have to be fixed for 6.3 since those things were already there from before. |
I noticed that gmtmath were unable to free datasets it had allocated because the tables never had their alloc_mode set to GMT_ALLOC_INTERNALLY. No error related to this, just a memory leak I am trying to track down in gmtmath.c and this is part of it.