Skip to content

Commit

Permalink
Feature GMT: only free dynamic geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
cburstedde committed Feb 19, 2024
1 parent 23fdf56 commit 172e449
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
10 changes: 9 additions & 1 deletion example/gmt/gmt_models.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ p4est_gmt_model_sphere_new (int resolution, const char *input,
/* Assign geometry */
/* Note: the following allocates memory externally, rather than in sgeom. */
model->model_geom = p4est_geometry_new_sphere2d (model->conn, 1.0);
model->geom_allocated = 1;

/* set default output prefix */
if (output_prefix == NULL) {
Expand Down Expand Up @@ -544,6 +545,12 @@ p4est_gmt_model_sphere_new (int resolution, const char *input,
void
p4est_gmt_model_destroy (p4est_gmt_model_t * model)
{
/* free geometry when dynamically allocated */
if (model->geom_allocated) {
p4est_geometry_destroy (model->model_geom);
}

/* free model-specific data */
if (model->destroy_data != NULL) {
/* only needed for non-trivial free code */
model->destroy_data (model->model_data);
Expand All @@ -552,7 +559,8 @@ p4est_gmt_model_destroy (p4est_gmt_model_t * model)
/* the default clears a standard allocation or respects NULL */
P4EST_FREE (model->model_data);
}
p4est_geometry_destroy (model->model_geom);

/* destroy connectivity outside of the specific model */
p4est_connectivity_destroy (model->conn);
P4EST_FREE (model);
}
5 changes: 4 additions & 1 deletion example/gmt/gmt_models.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ typedef struct p4est_gmt_model
/** Intersect a given rectangle with a model object. */
p4est_gmt_intersect_t intersect;

/** Private geometry data. */
/** True if we are not using the static geometry. */
int geom_allocated;

/** Private static geometry data. */
p4est_geometry_t sgeom;
}
p4est_gmt_model_t;
Expand Down

0 comments on commit 172e449

Please sign in to comment.