diff --git a/misc/m.nviz.image/surface.c b/misc/m.nviz.image/surface.c index a4b7c836c8f..6d396ca5804 100644 --- a/misc/m.nviz.image/surface.c +++ b/misc/m.nviz.image/surface.c @@ -27,7 +27,8 @@ */ int load_rasters(const struct GParams *params, nv_data *data) { - const char *mapset; + const char *mapset = NULL; + char *mname = NULL; int i; int nelevs, nelev_map, nelev_const, ncolor_map, ncolor_const, nmask_map; int ntransp_map, ntransp_const, nshine_map, nshine_const; @@ -50,11 +51,10 @@ int load_rasters(const struct GParams *params, nv_data *data) G_fatal_error(_("Raster map <%s> not found"), params->elev_map->answers[i]); } - - id = Nviz_new_map_obj( - MAP_OBJ_SURF, - G_fully_qualified_name(params->elev_map->answers[i], mapset), - 0.0, data); + mname = + G_fully_qualified_name(params->elev_map->answers[i], mapset); + id = Nviz_new_map_obj(MAP_OBJ_SURF, mname, 0.0, data); + G_free(mname); } else { if (i - nelev_map < nelev_const && @@ -107,10 +107,11 @@ int load_rasters(const struct GParams *params, nv_data *data) G_fatal_error(_("Raster map <%s> not found"), params->color_map->answers[i]); } - Nviz_set_attr( - id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT, - G_fully_qualified_name(params->color_map->answers[i], mapset), - -1.0, data); + mname = + G_fully_qualified_name(params->color_map->answers[i], mapset); + Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT, mname, -1.0, + data); + G_free(mname); } /* check for color value */ else if (i - ncolor_map < ncolor_const && @@ -122,14 +123,14 @@ int load_rasters(const struct GParams *params, nv_data *data) } else { /* use by default elevation map for coloring */ if (nelev_map > 0) { - Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT, - G_fully_qualified_name( - params->elev_map->answers[i], mapset), - -1.0, data); + mname = G_fully_qualified_name(params->elev_map->answers[i], + mapset); + Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT, mname, -1.0, + data); G_verbose_message( _("Color attribute not defined, using default <%s>"), - G_fully_qualified_name(params->elev_map->answers[i], - mapset)); + mname); + G_free(mname); } else { G_fatal_error(_("Missing color attribute for surface %d"), @@ -138,18 +139,20 @@ int load_rasters(const struct GParams *params, nv_data *data) } /* mask */ if (i < nmask_map && strcmp(params->mask_map->answers[i], "")) { - Nviz_set_attr( - id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT, - G_fully_qualified_name(params->mask_map->answers[i], mapset), - -1.0, data); + mname = + G_fully_qualified_name(params->mask_map->answers[i], mapset); + Nviz_set_attr(id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT, mname, -1.0, + data); + G_free(mname); } /* transparency */ if (i < ntransp_map && strcmp(params->transp_map->answers[i], "")) { - Nviz_set_attr( - id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT, - G_fully_qualified_name(params->transp_map->answers[i], mapset), - -1.0, data); + mname = + G_fully_qualified_name(params->transp_map->answers[i], mapset); + Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT, mname, -1.0, + data); + G_free(mname); } else if (i - ntransp_map < ntransp_const && strcmp(params->transp_const->answers[i - ntransp_map], "")) { @@ -160,10 +163,11 @@ int load_rasters(const struct GParams *params, nv_data *data) /* shininess */ if (i < nshine_map && strcmp(params->shine_map->answers[i], "")) { - Nviz_set_attr( - id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT, - G_fully_qualified_name(params->shine_map->answers[i], mapset), - -1.0, data); + mname = + G_fully_qualified_name(params->shine_map->answers[i], mapset); + Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT, mname, -1.0, + data); + G_free(mname); } else if (i - nshine_map < nshine_const && strcmp(params->shine_const->answers[i - nshine_map], "")) { @@ -174,10 +178,11 @@ int load_rasters(const struct GParams *params, nv_data *data) /* emission */ if (i < nemit_map && strcmp(params->emit_map->answers[i], "")) { - Nviz_set_attr( - id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT, - G_fully_qualified_name(params->emit_map->answers[i], mapset), - -1.0, data); + mname = + G_fully_qualified_name(params->emit_map->answers[i], mapset); + Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT, mname, -1.0, + data); + G_free(mname); } else if (i - nemit_map < nemit_const && strcmp(params->emit_const->answers[i - nemit_map], "")) { @@ -191,6 +196,7 @@ int load_rasters(const struct GParams *params, nv_data *data) set_default_wirecolors(data, i); */ } + G_free(surf_list); return nsurfs; } @@ -273,6 +279,7 @@ void surface_set_draw_mode(const struct GParams *params) /* wire color */ GS_set_wire_color(id, Nviz_color_from_str(wire_color)); } + G_free(surf_list); return; } diff --git a/misc/m.nviz.image/vector.c b/misc/m.nviz.image/vector.c index 655f39fa225..80e2c32165f 100644 --- a/misc/m.nviz.image/vector.c +++ b/misc/m.nviz.image/vector.c @@ -72,6 +72,7 @@ int load_vectors(const struct Option *elev_map, const struct Option *elev_const, surf_list = GS_get_surf_list(&nsurf); GS_set_att_const(surf_list[0], ATT_TRANSP, 255); + G_free(surf_list); } nvects = 0; @@ -81,9 +82,9 @@ int load_vectors(const struct Option *elev_map, const struct Option *elev_const, if (mapset == NULL) { G_fatal_error(_("Vector map <%s> not found"), vect->answers[i]); } - id = Nviz_new_map_obj(map_obj_type, - G_fully_qualified_name(vect->answers[i], mapset), - 0.0, data); + char *mname = G_fully_qualified_name(vect->answers[i], mapset); + id = Nviz_new_map_obj(map_obj_type, mname, 0.0, data); + G_free(mname); /* set position */ x = atof(position->answers[i * 3 + 0]); @@ -111,7 +112,7 @@ int load_vectors(const struct Option *elev_map, const struct Option *elev_const, */ int vlines_set_attrb(const struct GParams *params) { - int i, layer, color, width, flat, height; + int i, layer = 0, color, width, flat, height; int *vect_list, nvects; int have_colors; @@ -138,8 +139,10 @@ int vlines_set_attrb(const struct GParams *params) flat = 0; /* style (mode -- use memory by default) */ - if (GV_set_style(vect_list[i], TRUE, color, width, flat) < 0) + if (GV_set_style(vect_list[i], TRUE, color, width, flat) < 0) { + G_free(vect_list); return 0; + } /* check for vector color table */ have_colors = Vect_read_colors(params->vlines->answers[i], "", &colors); @@ -147,14 +150,17 @@ int vlines_set_attrb(const struct GParams *params) if (have_colors || color_column || width_column) if (GV_set_style_thematic(vect_list[i], layer, color_column, width_column, - have_colors ? &colors : NULL) < 0) + have_colors ? &colors : NULL) < 0) { + G_free(vect_list); return 0; + } /* height */ height = atoi(params->vline_height->answers[i]); if (height > 0) GV_set_trans(vect_list[i], 0.0, 0.0, height); } + G_free(vect_list); return 1; } @@ -169,7 +175,7 @@ int vlines_set_attrb(const struct GParams *params) */ int vpoints_set_attrb(const struct GParams *params) { - int i, layer, have_colors, with_z; + int i, have_colors; int *site_list, nsites; int marker, color, width; float size; @@ -181,6 +187,7 @@ int vpoints_set_attrb(const struct GParams *params) site_list = GP_get_site_list(&nsites); for (i = 0; i < nsites; i++) { + int layer = -1, with_z = 0; check_map(params, i, FALSE, &layer, &with_z); color = Nviz_color_from_str(params->vpoint_color->answers[i]); @@ -208,8 +215,10 @@ int vpoints_set_attrb(const struct GParams *params) GP_set_zmode(site_list[i], TRUE); } - if (GP_set_style(site_list[i], color, width, size, marker) < 0) + if (GP_set_style(site_list[i], color, width, size, marker) < 0) { + G_free(site_list); return 0; + } /* check for vector color table */ have_colors = @@ -219,10 +228,13 @@ int vpoints_set_attrb(const struct GParams *params) marker_column) { if (GP_set_style_thematic(site_list[i], layer, color_column, width_column, size_column, marker_column, - have_colors ? &colors : NULL) < 0) + have_colors ? &colors : NULL) < 0) { + G_free(site_list); return 0; + } } } + G_free(site_list); return 1; } @@ -251,6 +263,7 @@ int check_map(const struct GParams *params, int index, int vlines, int *field, Fi = NULL; driver = NULL; + column = NULL; if (vlines) { map = params->vlines->answers[index]; @@ -310,6 +323,8 @@ int check_map(const struct GParams *params, int index, int vlines, int *field, if (db_column_Ctype(driver, Fi->table, color) != DB_C_TYPE_STRING) G_fatal_error(_("Data type of color column must be character")); + db_free_column(column); + column = NULL; } if (size) { db_get_column(driver, Fi->table, size, &column); @@ -320,6 +335,8 @@ int check_map(const struct GParams *params, int index, int vlines, int *field, type = db_column_Ctype(driver, Fi->table, size); if (type != DB_C_TYPE_INT && type != DB_C_TYPE_DOUBLE) G_fatal_error(_("Data type of size column must be numeric")); + db_free_column(column); + column = NULL; } if (width) { db_get_column(driver, Fi->table, width, &column); @@ -330,6 +347,8 @@ int check_map(const struct GParams *params, int index, int vlines, int *field, type = db_column_Ctype(driver, Fi->table, width); if (type != DB_C_TYPE_INT && type != DB_C_TYPE_DOUBLE) G_fatal_error(_("Data type of width column must be numeric")); + db_free_column(column); + column = NULL; } if (marker) { db_get_column(driver, Fi->table, marker, &column); @@ -341,9 +360,12 @@ int check_map(const struct GParams *params, int index, int vlines, int *field, if (db_column_Ctype(driver, Fi->table, marker) != DB_C_TYPE_STRING) G_fatal_error( _("Data type of marker column must be character")); + db_free_column(column); + column = NULL; } db_close_database_shutdown_driver(driver); + Vect_destroy_field_info(Fi); } Vect_close(&Map); diff --git a/misc/m.nviz.image/volume.c b/misc/m.nviz.image/volume.c index cff9b5b53ab..262f7cee7d5 100644 --- a/misc/m.nviz.image/volume.c +++ b/misc/m.nviz.image/volume.c @@ -42,11 +42,10 @@ int load_rasters3d(const struct GParams *params, nv_data *data) G_fatal_error(_("3d raster map <%s> not found"), params->volume->answers[i]); } - - id = Nviz_new_map_obj( - MAP_OBJ_VOL, - G_fully_qualified_name(params->volume->answers[i], mapset), 0.0, - data); + char *mname = + G_fully_qualified_name(params->volume->answers[i], mapset); + id = Nviz_new_map_obj(MAP_OBJ_VOL, mname, 0.0, data); + G_free(mname); /* set position */ if (opt_get_num_answers(params->volume_pos) != 3 * nvol) { @@ -243,6 +242,7 @@ int add_isosurfs(const struct GParams *params, nv_data *data UNUSED) GVL_isosurf_set_drawmode(id, draw_mode); } + G_free(vol_list); return 1; } @@ -331,6 +331,7 @@ int add_slices(const struct GParams *params, nv_data *data UNUSED) GVL_slice_set_drawmode(id, draw_mode); } + G_free(vol_list); return 1; }