Skip to content

Commit

Permalink
libvector/neta: fix memory leaks (OSGeo#3618)
Browse files Browse the repository at this point in the history
  • Loading branch information
nilason authored Jun 22, 2024
1 parent acee505 commit af6e7da
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/vector/neta/articulation_point.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,6 @@ int NetA_articulation_points(dglGraph_s *graph, struct ilist *articulation_list)
G_free(parent);
G_free(stack);
G_free(current_edge);
G_free(mark);
return points;
}
10 changes: 9 additions & 1 deletion lib/vector/neta/timetables.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ int NetA_init_distinct(dbDriver *driver, dbString *sql, int **lengths,
G_warning(_("Out of memory"));
return -1;
}
db_open_select_cursor(driver, sql, &cursor, DB_SEQUENTIAL);
if (db_open_select_cursor(driver, sql, &cursor, DB_SEQUENTIAL) != DB_OK) {
G_warning(_("Unable to open select cursor: %s"), db_get_string(sql));
return -1;
}
count = index = 0;
/*calculate the lengths of the routes */
table = db_get_cursor_table(&cursor);
Expand Down Expand Up @@ -128,6 +131,10 @@ int NetA_init_timetable_from_db(struct Map_info *In, int route_layer,
struct field_info *Fi;

Fi = Vect_get_field(In, route_layer);
if (Fi == NULL)
G_fatal_error(_("Database connection not defined for layer %d"),
route_layer);

driver = db_start_driver_open_database(Fi->driver, Fi->database);
if (driver == NULL)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
Expand Down Expand Up @@ -308,6 +315,7 @@ int NetA_init_timetable_from_db(struct Map_info *In, int route_layer,
}
db_close_cursor(&cursor);
}
Vect_destroy_field_info(Fi);
db_close_database_shutdown_driver(driver);

return 0;
Expand Down
18 changes: 13 additions & 5 deletions lib/vector/neta/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,31 @@ int NetA_get_node_costs(struct Map_info *In, int layer, char *column,
struct field_info *Fi;

Fi = Vect_get_field(In, layer);
if (Fi == NULL)
G_fatal_error(_("Database connection not defined for layer %d"), layer);

driver = db_start_driver_open_database(Fi->driver, Fi->database);
if (driver == NULL)
G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
Fi->database, Fi->driver);

nlines = Vect_get_num_lines(In);
nnodes = Vect_get_num_nodes(In);
Cats = Vect_new_cats_struct();
Points = Vect_new_line_struct();
for (i = 1; i <= nnodes; i++)
node_costs[i] = 0;

db_CatValArray_init(&vals);
int nvals =
db_select_CatValArray(driver, Fi->table, Fi->key, column, NULL, &vals);

db_close_database_shutdown_driver(driver);
Vect_destroy_field_info(Fi);

if (db_select_CatValArray(driver, Fi->table, Fi->key, column, NULL,
&vals) == -1)
if (nvals == -1)
return 0;

Cats = Vect_new_cats_struct();
Points = Vect_new_line_struct();
for (i = 1; i <= nlines; i++) {
int type = Vect_read_line(In, Points, Cats, i);

Expand All @@ -152,8 +160,8 @@ int NetA_get_node_costs(struct Map_info *In, int layer, char *column,
}

Vect_destroy_cats_struct(Cats);
Vect_destroy_line_struct(Points);
db_CatValArray_free(&vals);
db_close_database_shutdown_driver(driver);
return 1;
}

Expand Down

0 comments on commit af6e7da

Please sign in to comment.