Skip to content

Commit

Permalink
Plug memory leak in dlx_remove_row().
Browse files Browse the repository at this point in the history
  • Loading branch information
blynn committed Feb 16, 2022
1 parent 5f73ef1 commit f7626af
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions dlx.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,21 @@ dlx_t dlx_new() {
return p;
}

void free_row(cell_ptr r) {
cell_ptr next;
for(cell_ptr j = r->R; j != r; j = next) {
next = j->R;
free(j);
}
free(r);
}

void dlx_clear(dlx_t p) {
// Elements in the LR list for each row are never covered, thus all cells
// can be accessed from the 'rtab' LR lists.
F(i, p->rtabn) {
cell_ptr r = p->rtab[i];
if (r) {
cell_ptr next;
for(cell_ptr j = r->R; j != r; j = next) {
next = j->R;
free(j);
}
free(r);
}
if (r) free_row(r);
}
// Columns may be covered, but they are always accessible from 'ctab'.
F(i, p->ctabn) free(p->ctab[i]);
Expand Down Expand Up @@ -177,6 +179,7 @@ int dlx_remove_row(dlx_t p, int i) {
UD_delete(j)->c->s--;
}
p->rtab[i] = 0;
free_row(r);
return 0;
}

Expand Down

0 comments on commit f7626af

Please sign in to comment.