segfault when calling gvLayout()

I'm doing the following things with the graphviz C library:

Agraph_t *graph;
GVC_t *ctx;
ctx = gvContext();
graph = agopen(filename, Agdirected, NULL);
/* I then add some nodes with */
agnode(graph, node_str, FALSE);
/* and some edges with */
agedge(graph, src_node, dst_node, edge_name, TRUE);
gvLayout(ctx, graph, "dot");

When I read the gvLayout() part it goes segfault. What could be the problem?
I've tried not adding nodes and edges to the graph. It doesn't blow up, but valgrind show severe memory leaks although I call these after:
gvRenderFilename (ctx, graph, "svg", filename);
gvFreeLayout(ctx, graph);
agclose (graph);

agnode(graph, node_str,

agnode(graph, node_str, FALSE) does not create a node; it returns a node if it exists and NULL otherwise. This causes a crash when you pass the NULL node pointers to agedge(). (One could argue that agedge should catch and report this.) In any case, use agnode(graph,node_str,TRUE) to create a node if it doesn't exist.

What about those memory leaks

What about those memory leaks when I don't add anything to the graph?

I don't get it why they appear.

I'll check again, but most of

I'll check again, but most of the leaks reported by valgrind are usually in third-party libraries like cairo and pango, over which we have no control.

Recent comments