Skip to content

Graphviz doesn't clear context completely

Steps to reproduce

Two files - dot.c and example.dot.

dot.c:

#include <graphviz/gvc.h>
#include <stdio.h>

int dot(int argc, char *argv[]) {
    GVC_t *gvc = gvContext();
    gvParseArgs(gvc, argc, argv);
    graph_t *g, *prev = NULL;
    while ((g = gvNextInputGraph(gvc))) {
        if (prev) {
            gvFreeLayout(gvc, prev);
            agclose(prev);
        }
        gvLayoutJobs(gvc, g);
        gvRenderJobs(gvc, g);
        prev = g;
    }
    gvFinalize(gvc);
    int result = gvFreeContext(gvc);
    return result;
}

int main(int argc, char *argv[]) {
    printf("Point 1");
    dot(argc, argv);
    printf("Point 2");
    dot(argc, argv);
    printf("Point 3");
    dot(argc, argv);
}

example.dot:

digraph D {

  A [shape=diamond]
  B [shape=box]
  C [shape=circle]

  A -> B [style=dashed, color=grey]
  A -> C [color="black:invis:black"]
  A -> D [penwidth=5, arrowhead=none]
}

Expected Behaviour

When dot.c is compiled and run using: ./dot -Tpng ./example.dot -o example.png it must create file example.png three times (each time overwriting it) and program must terminate without any erros.

Actual Behaviour

Program terminates with: Error: Segmentation fault (core dumped)

OS Version

Ubuntu 20.04.3 LTS

Graphviz Version

Graphviz 9.0.0 from https://gitlab.com/api/v4/projects/4207231/packages/generic/graphviz-releases/9.0.0/ubuntu_20.04_graphviz-9.0.0-cmake.deb

Additional info

I want to use graphviz in java library, so I call dot function from Java using JNI. And it is very important for me that graphviz not to save states between calls.