Skip to content

Commit

Permalink
Merge pull request #20 from krychu/#19-memory-leak
Browse files Browse the repository at this point in the history
Properly free duplicate tiles
  • Loading branch information
krychu authored Mar 23, 2022
2 parents b1b2c42 + 25a50fa commit 38b08ab
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion wfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,18 @@ static int wfc__remove_duplicate_tiles(struct wfc__tile **tiles, int *tile_cnt)
}

if (unique) {
(*tiles)[unique_cnt] = (*tiles)[j];
if (unique_cnt != j) {
struct wfc__tile tmp = (*tiles)[unique_cnt];
(*tiles)[unique_cnt] = (*tiles)[j];
(*tiles)[j] = tmp;
}
unique_cnt++;
}
}

for (int i=unique_cnt; i<*tile_cnt; i++)
wfc_img_destroy((*tiles)[i].image);

struct wfc__tile *unique_tiles = realloc(*tiles, sizeof(**tiles) * unique_cnt);
if (unique_tiles == NULL) {
p("wfc__remove_duplicate_tiles: error\n");
Expand Down

0 comments on commit 38b08ab

Please sign in to comment.