From ef83b4f829a129dfcfc7b5e6db740b9566e1814d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Fri, 2 Mar 2012 19:00:59 +0100 Subject: [PATCH] Explicitly relinquish resources from processed_grid conveyed onto the UnstructuredGrid. This enables calling free_processed_grid() at the end of preprocess(), whence all resources allocated in process_grdecl() and present in the processed_grid can be properly disposed of, even in case of extending the processed_grid structure. --- opm/core/utility/cpgpreprocess/cgridinterface.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/opm/core/utility/cpgpreprocess/cgridinterface.c b/opm/core/utility/cpgpreprocess/cgridinterface.c index 52c780f7..1773ddee 100644 --- a/opm/core/utility/cpgpreprocess/cgridinterface.c +++ b/opm/core/utility/cpgpreprocess/cgridinterface.c @@ -203,6 +203,14 @@ preprocess (const struct grdecl *in, double tol) g->face_nodepos = pg.face_ptr; g->face_cells = pg.face_neighbors; + /* Explicitly relinquish resource references conveyed to 'g'. This + * is needed to avoid creating dangling references in the + * free_processed_grid() call. */ + pg.node_coordinates = NULL; + pg.face_nodes = NULL; + pg.face_ptr = NULL; + pg.face_neighbors = NULL; + g->face_centroids = NULL; g->face_normals = NULL; g->face_areas = NULL; @@ -235,7 +243,14 @@ preprocess (const struct grdecl *in, double tol) g->cartdims[2] = pg.dimensions[2]; g->global_cell = pg.local_cell_index; + + /* Explicitly relinquish resource references conveyed to 'g'. + * This is needed to avoid creating dangling references in the + * free_processed_grid() call. */ + pg.local_cell_index = NULL; } + free_processed_grid(&pg); + return g; }