rem: if (reload && screen.file[idx]) { free_gerb_image(screen.file[idx]->image); screen.file[idx]->image = NULL; } else { screen.file[idx] = (gerbv_fileinfo_t *)malloc(sizeof(gerbv_fileinfo_t)); }
context: open_image(char *filename, int idx, int reload){    gerb_file_t *fd;    int r, g, b;    GtkStyle *defstyle, *newstyle;    gerb_verify_error_t error = GERB_IMAGE_OK;    char *cptr;    if (idx >= MAX_FILES) {	fprintf(stderr, "Couldn't open %s. Maximum number of files opened.\n",		filename);	return -1;    }    fd = gerb_fopen(filename);    if (fd == NULL) {	fprintf(stderr, "Trying to open %s: ", filename);	perror("");	return -1;    }        if (reload && screen.file[idx]) {	free_gerb_image(screen.file[idx]->image);  	screen.file[idx]->image = NULL;    } else {	screen.file[idx] = (gerbv_fileinfo_t *)malloc(sizeof(gerbv_fileinfo_t));    }        if(drill_file_p(fd))	screen.file[idx]->image = parse_drillfile(fd);    else 	screen.file[idx]->image = parse_gerb(fd);    gerb_fclose(fd);    /*     * Do some cleanup if error check below fails     */    screen.file[idx]->color = NULL;    screen.file[idx]->name  = NULL;    /*     * Do error check before continuing     */    error = gerb_image_verify(screen.file[idx]->image);    if (error) {	fprintf(stderr, "%s: Parse error: ", filename);	if (error & GERB_IMAGE_MISSING_NETLIST)	    fprintf(stderr, "Missing netlist ");	if (error & GERB_IMAGE_MISSING_FORMAT)	    fprintf(stderr, "Missing format ");	if (error & GERB_IMAGE_MISSING_APERTURES) 	    fprintf(stderr, "Missing apertures/drill sizes ");	if (error & GERB_IMAGE_MISSING_INFO)	    fprintf(stderr, "Missing info ");	fprintf(stderr, "\n");	fprintf(stderr, "You probably tried to read an RS-274D file, which gerbv doesn't support\n");	return -1;    }    if (reload) return 0; /* Stop here if we do a reload of files */    /*     * Store filename for eventual reload     * XXX Really should check retval from malloc!!! And use strncpy     */    screen.file[idx]->name = (char *)malloc(strlen(filename) + 1);    strcpy(screen.file[idx]->name, filename);    /*     * Try to get a basename for the file     */    cptr = strrchr(filename, '/');    if (cptr) {	int len;	len = strlen(cptr);	screen.file[idx]->basename = (char *)malloc(len + 1);	if (screen.file[idx]->basename) {	    strncpy(screen.file[idx]->basename, cptr+1, len);	    screen.file[idx]->basename[len] = '\0';	} else {	    screen.file[idx]->basename = screen.file[idx]->name;	}    } else {	screen.file[idx]->basename = screen.file[idx]->name;    }    /*     * Calculate a "clever" random color based on index.     */    r = (12341 + 657371 * idx) % (int)(MAX_COLOR_RESOLUTION);    g = (23473 + 434382 * idx) % (int)(MAX_COLOR_RESOLUTION);    b = (90341 + 123393 * idx) % (int)(MAX_COLOR_RESOLUTION);    screen.file[idx]->color = alloc_color(r, g, b, NULL);    /*      * Set color on layer button     */    defstyle = gtk_widget_get_default_style();    newstyle = gtk_style_copy(defstyle);    newstyle->bg[GTK_STATE_NORMAL] = *(screen.file[idx]->color);    newstyle->bg[GTK_STATE_ACTIVE] = *(screen.file[idx]->color);    newstyle->bg[GTK_STATE_PRELIGHT] = *(screen.file[idx]->color);    gtk_widget_set_style(screen.layer_button[idx], newstyle);    /*      * Tool tips on button is the file name      */    gtk_tooltips_set_tip(screen.tooltips, screen.layer_button[idx],			 filename, NULL);     return 0;} /* open_image */