Layout again after rendering phase

What do I have to do that I can layout again after a render phase?

GVC_t * gvc = gvContext();
Agraph * g = makeGraph(); /* own function, converts data */
gvLayout(gvc, g, "sfdp");
gvRender(gvc, g, "dot", NULL); /* dont render in file */

/* Nodes in graph now contain "pos" attributes */

/* I would like to add some nodes here */
/* But in actual code this is empty */
doSomething(gvc, g);

/* Repeat */
gvLayout(gvc, g, "sfdp");
gvRenderFilename(gvc, g, "dot", "output.dot");

gvFreeLayout(gvc, g);
agclose(g); /* CRASH HERE */
return gvFreeContext(gvc);

It crashes at "agclose(g)". Do I have to free the layout? make a new gvc context? I tried different thing, but all crash :(

Oh I did agflatten(g, TRUE);

Oh I did

agflatten(g, TRUE); /* flat-out efficiency */

somewhere in code, maybe that caused the crash

My first guess is that you

My first guess is that you have to call gvFreeLayout before doing a second layout. See the second paragraph on page 21 of http://www.graphviz.org/doc/libguide/libguide.pdf