in src/backend/utils/adt/age_global_graph.c [700:813]
static bool free_specific_GRAPH_global_context(GRAPH_global_context *ggctx)
{
GraphIdNode *curr_vertex = NULL;
GraphIdNode *curr_edge = NULL;
/* don't do anything if NULL */
if (ggctx == NULL)
{
return true;
}
/* free the graph name */
pfree_if_not_null(ggctx->graph_name);
ggctx->graph_name = NULL;
ggctx->graph_oid = InvalidOid;
ggctx->next = NULL;
/* free the vertex edge lists and properties, starting with the head */
curr_vertex = peek_stack_head(ggctx->vertices);
while (curr_vertex != NULL)
{
GraphIdNode *next_vertex = NULL;
vertex_entry *value = NULL;
bool found = false;
graphid vertex_id;
/* get the next vertex in the list, if any */
next_vertex = next_GraphIdNode(curr_vertex);
/* get the current vertex id */
vertex_id = get_graphid(curr_vertex);
/* retrieve the vertex entry */
value = (vertex_entry *)hash_search(ggctx->vertex_hashtable,
(void *)&vertex_id, HASH_FIND,
&found);
/* this is bad if it isn't found, but leave that to the caller */
if (found == false)
{
return false;
}
/* free the vertex's datumCopy properties */
pfree_if_not_null(DatumGetPointer(value->vertex_properties));
value->vertex_properties = 0;
/* free the edge list associated with this vertex */
free_ListGraphId(value->edges_in);
free_ListGraphId(value->edges_out);
free_ListGraphId(value->edges_self);
value->edges_in = NULL;
value->edges_out = NULL;
value->edges_self = NULL;
/* move to the next vertex */
curr_vertex = next_vertex;
}
/* free the edge properties, starting with the head */
curr_edge = peek_stack_head(ggctx->edges);
while (curr_edge != NULL)
{
GraphIdNode *next_edge = NULL;
edge_entry *value = NULL;
bool found = false;
graphid edge_id;
/* get the next edge in the list, if any */
next_edge = next_GraphIdNode(curr_edge);
/* get the current edge id */
edge_id = get_graphid(curr_edge);
/* retrieve the edge entry */
value = (edge_entry *)hash_search(ggctx->edge_hashtable,
(void *)&edge_id, HASH_FIND,
&found);
/* this is bad if it isn't found, but leave that to the caller */
if (found == false)
{
return false;
}
/* free the edge's datumCopy properties */
pfree_if_not_null(DatumGetPointer(value->edge_properties));
value->edge_properties = 0;
/* move to the next edge */
curr_edge = next_edge;
}
/* free the vertices list */
free_ListGraphId(ggctx->vertices);
ggctx->vertices = NULL;
/* free the edges list */
free_ListGraphId(ggctx->edges);
ggctx->edges = NULL;
/* free the hashtables */
hash_destroy(ggctx->vertex_hashtable);
hash_destroy(ggctx->edge_hashtable);
ggctx->vertex_hashtable = NULL;
ggctx->edge_hashtable = NULL;
/* free the context */
pfree_if_not_null(ggctx);
ggctx = NULL;
return true;
}