I have a version of the code that I ran through valgrind and it passes my tests. I think that valgrind would catch any double open. My version with fixes is here: https://github.com/eyal0/gerbv Let me know if that fixes it for you, too.
I fixed it on my own branch in github: https://github.com/eyal0/gerbv/commit/957603baeaba04a7368391e8d8229cb85fda2ee3
More details here: https://stackoverflow.com/questions/65412785/multiple-definition-error-when-linking-c-but-only-on-mingw
I see this bug, too. The problem will only occur under new versions of gcc where -fno-common is now the default. The solution is to modify the definition of CALLBACKS_SAVE_FILE_TYPE. Instead of: enum { ... } CALLBACKS_SAVE_FILE_TIME; it should be enum CALLBACKS_SAVE_FILE_TIME { ... }; There are other enums in the same file that need the same treatment.
Ah, wait, there is another: @@ -1119,6 +1120,7 @@ drill_parse_T_code(gerb_file_t *fd, drill_state_t *state, /* Set the current tool to the correct one */ state->current_tool = tool_num; + apert = image->aperture[tool_num]; /* Check for a size definition */ temp = gerb_fgetc(fd); @@ -1155,7 +1157,6 @@ drill_parse_T_code(gerb_file_t *fd, drill_state_t *state, "at line %ld in file \"%s\""), size, tool_num, file_line, fd->filename); } else { - apert = image->aperture[tool_num]; if (apert != NULL) { /*...
Great! Would you also like to fix memory leaks and the reading of uninitialized memory? https://sourceforge.net/p/gerbv/bugs/250/ If you fix those then you will have fixed all of the memory leaks and memory errors that valgrind found when running pcb2gcode.
diff --git a/src/gerb_image.c b/src/gerb_image.c index 5e66e73..88458e6 100644 --- a/src/gerb_image.c +++ b/src/gerb_image.c @@ -173,6 +173,7 @@ gerbv_destroy_image(gerbv_image_t *image) gerbv_layer_t *tempLayer = layer; layer = layer->next; + g_free (tempLayer->name); g_free (tempLayer); } for (state = image->states; state != NULL; ) { @@ -312,6 +313,7 @@ gerbv_image_return_new_layer (gerbv_layer_t *previousLayer) previousLayer->next = newLayer; /* clear this boolean so we only draw the knockout...
diff --git a/src/gerb_image.c b/src/gerb_image.c index 5e66e73..88458e6 100644 --- a/src/gerb_image.c +++ b/src/gerb_image.c @@ -173,6 +173,7 @@ gerbv_destroy_image(gerbv_image_t image) gerbv_layer_t tempLayer = layer; layer = layer->next; g_free (tempLayer->name); g_free (tempLayer); } for (state = image->states; state != NULL; ) { @@ -312,6 +313,7 @@ gerbv_image_return_new_layer (gerbv_layer_t previousLayer) previousLayer->next = newLayer; / clear this boolean so we only draw the knockout once...