Skip to content

Commit

Permalink
skip: fix buffer memory freeing
Browse files Browse the repository at this point in the history
First, there was a subtle memory leak in weird use cases of ts_read_mt()
that should never happen anyways, but oh well. That's fixed.

And we had accessed non-allocated memory when ts_read_mt() was not used
in our finish function.
  • Loading branch information
merge committed Mar 13, 2017
1 parent da5477e commit de5e261
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions plugins/skip.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ static int skip_read_mt(struct tslib_module_info *info,
if (skip->buf_mt[i])
free(skip->buf_mt[i]);
}
free(skip->buf_mt);
}

skip->buf_mt = malloc(skip->ntail *
Expand Down Expand Up @@ -301,21 +302,24 @@ static int skip_fini(struct tslib_module_info *info)
if (skip->buf)
free(skip->buf);

for (i = 0; i < skip->ntail; i++) {
if (skip->buf_mt[i])
free(skip->buf_mt[i]);
if (skip->buf_mt) {
for (i = 0; i < skip->ntail; i++) {
if (skip->buf_mt[i])
free(skip->buf_mt[i]);
}
free(skip->buf_mt);
}

if (skip->buf_mt)
free(skip->buf_mt);

if (skip->cur_mt && skip->cur_mt[0])
free(skip->cur_mt[0]);

if (skip->cur_mt)
free(skip->cur_mt);

free(info);
if (info)
free(info);

return 0;
}
Expand Down

0 comments on commit de5e261

Please sign in to comment.