Skip to content

Commit

Permalink
Set segment's alloc_mode_text so we can free it (#7758)
Browse files Browse the repository at this point in the history
LIke the dtata colums has S_>alloc_mode[col], the optional trailing text has alloc_mode_text but like all alloc)modes it defaults to EXTERNAL and needs to be set to INTERNAL when GMT is filling them in - otherwise we get a memory leaka.
a
  • Loading branch information
PaulWessel authored Aug 24, 2023
1 parent 0ee4b57 commit d6f44a7
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/gmt_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -7919,6 +7919,7 @@ int gmt_alloc_segment (struct GMT_CTRL *GMT, struct GMT_DATASEGMENT *S, uint64_t
GMT_Report (GMT->parent, GMT_MSG_ERROR, "gmt_alloc_segment: Unable to reallocate string array new length %" PRIu64 "\n", n_rows);
return 1;
}
SH->alloc_mode_text = GMT_ALLOC_INTERNALLY;
}
SH->n_alloc = n_rows;
}
Expand Down Expand Up @@ -7954,6 +7955,7 @@ void gmtlib_assign_segment (struct GMT_CTRL *GMT, unsigned int direction, struct
GMT->hidden.mem_txt = gmt_M_memory (GMT, GMT->hidden.mem_txt, n_rows, char *); /* Trim back */
S->text = GMT->hidden.mem_txt; /* Pass the pointer */
GMT->hidden.mem_txt = NULL; /* Null this out to start over for next segment */
SH->alloc_mode_text = GMT_ALLOC_INTERNALLY;
}
GMT->hidden.mem_cols = 0; /* Flag that we need to reallocate new temp arrays for next segment, if any */
}
Expand All @@ -7966,6 +7968,7 @@ void gmtlib_assign_segment (struct GMT_CTRL *GMT, unsigned int direction, struct
if (GMT->current.io.record_type[direction] & GMT_READ_TEXT) {
uint64_t row;
S->text = gmt_M_memory (GMT, S->text, n_rows, char *);
SH->alloc_mode_text = GMT_ALLOC_INTERNALLY;
for (row = 0; row < n_rows; row++) {
S->text[row] = GMT->hidden.mem_txt[row];
GMT->hidden.mem_txt[row] = NULL;
Expand Down

0 comments on commit d6f44a7

Please sign in to comment.