You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Figure.meca causes segmentation fault when given "event_name" via a DataFrame #2524
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
I ran this via Xcode etc but no crash, at least it did not stop at a line like yours. It ended with these message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/pwessel/UH/RESEARCH/CVSPROJECTS/GMTdev/pygmt/pygmt/helpers/decorators.py", line 598, in new_module
return module_func(*args, **kwargs)
File "/Users/pwessel/UH/RESEARCH/CVSPROJECTS/GMTdev/pygmt/pygmt/helpers/decorators.py", line 738, in new_module
return module_func(*args, **kwargs)
File "/Users/pwessel/UH/RESEARCH/CVSPROJECTS/GMTdev/pygmt/pygmt/src/meca.py", line 383, in meca
lib.call_module(module="meca", args=build_arg_string(kwargs, infile=fname))
File "/Users/pwessel/UH/RESEARCH/CVSPROJECTS/GMTdev/pygmt/pygmt/clib/session.py", line 621, in call_module
raise GMTCLibError(
pygmt.exceptions.GMTCLibError: Module 'meca' failed with status code 45:
Unfortunately, if not crashing on macOS you may have to run in ddd in Linux...
to create the data container, and then call GMT_Put_Vectors and GMT_Put_Strings (family=GMT_IS_VECTOR|GMT_IS_DUPLICATE) to put the vectors/strings into the container. This creates the API object 0:
--------------------------------------------------------
K.. ID RESOURCE.... FAMILY.... ACTUAL.... DIR... S O M L
--------------------------------------------------------
* 0 0 7fd069174830 Vector Vector Input 2 Y N 0
In the case GMT_IS_REFERENCE|GMT_VIA_VECTOR branch, the function creates a GMT_DATASET container and hooks up the vectors and the trailing text
...
S->data[col_pos_out] = V_obj->data[col_pos].f8;
SH->alloc_mode[col_pos_out] = GMT_ALLOC_EXTERNALLY;
...
if (smode) S->text = V_obj->text; /* Hook up trailing text array */
Now we have two API objects:
--------------------------------------------------------
K.. ID RESOURCE.... FAMILY.... ACTUAL.... DIR... S O M L
--------------------------------------------------------
* 0 0 7fd069174830 Vector Vector Input 2 Y N 0
* 1 1 60000203ad00 Data Table Data Table Input 2 Y N 1
--------------------------------------------------------
At the end of the psmeca module, we call the gmtlib_garbage_collection (and the gmtlib_free_dataset_ptr function) which frees the API object 1 (i.e., the Dataset container). The vector columns S->data[col] are not freed because alloc_mode[col] was set to GMT_ALLOC_EXTERNALLY, but the trailing text S->text are freed. It also frees the trailing texts of the original GMT_VECTOR object (i.e., V_obj->text) because S->text is a reference of V_obj->text.
Thus, at the end of the GMT session, when we try to free the API object 0 (i.e., V_obj->text), we see the pointer being freed was not allocated error.
I hope my understanding is correct and it can help you find a fix for this issue.
Not so. And, if I try to place a stop point in psmeca it never stops there, It stops in the places I asked (Put_Strings etc in the API) but pretty soon we are in the GarbageCollector and no evidence it ever went into meta. Not sure what to do.
Activity
welcome commentedon Apr 27, 2023
👋 Thanks for opening your first issue here! Please make sure you filled out the template with as much detail as possible. You might also want to take a look at our contributing guidelines and code of conduct.
wasjabloch commentedon Apr 27, 2023
P.S.: I just saw that
pygmt v0.9.0is out. I'll now try to confirm the bug with the most recent version.wasjabloch commentedon Apr 27, 2023
Confirmed with the most recent version. The bug report is now up to date.
seisman commentedon Apr 28, 2023
Thanks. I can reproduce the issue. Will see why it happens later.
seisman commentedon Jun 18, 2023
@PaulWessel This looks like an upstream bug to me, could you please see if you can verify and it?
Here is a minimal example to reproduce the issue:
Here are the verbose messages:
PaulWessel commentedon Jun 18, 2023
I ran this via Xcode etc but no crash, at least it did not stop at a line like yours. It ended with these message:
Unfortunately, if not crashing on macOS you may have to run in ddd in Linux...
seisman commentedon Jun 19, 2023
Here are my understanding of the issue:
In PyGMT, we first call
to create the data container, and then call
GMT_Put_VectorsandGMT_Put_Strings(family=GMT_IS_VECTOR|GMT_IS_DUPLICATE) to put the vectors/strings into the container. This creates the API object 0:Then in GMT, the
psmecamodule calls theGMT_Init_IOandGMT_Read_Datafunctions (L780 inpsmeca.chttps://github.com/GenericMappingTools/gmt/blob/8bf949a0ece1a3af56ba64e00cd979010d751854/src/seis/psmeca.c#L780). TheGMT_Read_Datafunction callsgmtapi_import_datasetand then we go to thecase GMT_IS_REFERENCE|GMT_VIA_VECTORbranch (https://github.com/GenericMappingTools/gmt/blob/8bf949a0ece1a3af56ba64e00cd979010d751854/src/gmt_api.c#L4091).In the
case GMT_IS_REFERENCE|GMT_VIA_VECTORbranch, the function creates aGMT_DATASETcontainer and hooks up the vectors and the trailing textNow we have two API objects:
At the end of the
psmecamodule, we call thegmtlib_garbage_collection(and thegmtlib_free_dataset_ptrfunction) which frees the API object 1 (i.e., the Dataset container). The vector columnsS->data[col]are not freed becausealloc_mode[col]was set toGMT_ALLOC_EXTERNALLY, but the trailing textS->textare freed. It also frees the trailing texts of the originalGMT_VECTORobject (i.e.,V_obj->text) becauseS->textis a reference ofV_obj->text.Thus, at the end of the GMT session, when we try to free the API object 0 (i.e.,
V_obj->text), we see thepointer being freed was not allocatederror.I hope my understanding is correct and it can help you find a fix for this issue.
PaulWessel commentedon Jun 19, 2023
Hm, since the data columns have their flag
SH->alloc_mode[col_pos_out] = GMT_ALLOC_EXTERNALLY; /* Not this objects job to free what was passed in by reference */it would seem we need a similar
alloc_modefor the trailing text to protect it. In gmt_hidden.h the GMT_DATASEGMENT_HIDDEN struct for datasegments hasSo I will add
and then consult this variable before free. Sees sensible?
seisman commentedon Jun 19, 2023
Yes, it will very likely fix the issue!
Do no free external trailing text strings
PaulWessel commentedon Jun 19, 2023
Not so. And, if I try to place a stop point in psmeca it never stops there, It stops in the places I asked (Put_Strings etc in the API) but pretty soon we are in the GarbageCollector and no evidence it ever went into meta. Not sure what to do.
seisman commentedon Jun 19, 2023
Your changes in PR GenericMappingTools/gmt#7557 work well for me after applying the changes in https://github.com/GenericMappingTools/gmt/pull/7557/files#r1234079875.
Do no free external trailing text strings (#7557)