Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak in brotlimt #355

Merged
merged 2 commits into from Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions C/zstdmt/brotli-mt_compress.c
Expand Up @@ -480,6 +480,15 @@ size_t BROTLIMT_compressCCtx(BROTLIMT_CCtx * ctx, BROTLIMT_RdWr_t * rdwr)
retval_of_thread = p;
}

/* move remaining done/busy entries to free list */
while (!list_empty(&ctx->writelist_done)) {
struct list_head *entry = list_first(&ctx->writelist_done);
list_move(entry, &ctx->writelist_free);
}
while (!list_empty(&ctx->writelist_busy)) {
struct list_head* entry = list_first(&ctx->writelist_busy);
list_move(entry, &ctx->writelist_free);
}
/* clean up lists */
while (!list_empty(&ctx->writelist_free)) {
struct writelist *wl;
Expand Down
22 changes: 13 additions & 9 deletions C/zstdmt/brotli-mt_decompress.c
Expand Up @@ -363,12 +363,7 @@ static void *pt_decompress(void *arg)
}

/* everything is okay */
pthread_mutex_lock(&ctx->write_mutex);
list_move(&wl->node, &ctx->writelist_free);
pthread_mutex_unlock(&ctx->write_mutex);
if (in->allocated)
free(in->buf);
return 0;
result = 0;

error_lock:
pthread_mutex_lock(&ctx->write_mutex);
Expand Down Expand Up @@ -508,8 +503,8 @@ size_t BROTLIMT_decompressDCtx(BROTLIMT_DCtx * ctx, BROTLIMT_RdWr_t * rdwr)
/* no pthread_create() needed! */
void *p = pt_decompress(w);
if (p)
return (size_t) p;
goto okay;
retval_of_thread = p;
goto done;
}

/* multi threaded */
Expand All @@ -530,7 +525,16 @@ size_t BROTLIMT_decompressDCtx(BROTLIMT_DCtx * ctx, BROTLIMT_RdWr_t * rdwr)
retval_of_thread = p;
}

okay:
done:
/* move remaining done/busy entries to free list */
while (!list_empty(&ctx->writelist_done)) {
struct list_head *entry = list_first(&ctx->writelist_done);
list_move(entry, &ctx->writelist_free);
}
while (!list_empty(&ctx->writelist_busy)) {
struct list_head* entry = list_first(&ctx->writelist_busy);
list_move(entry, &ctx->writelist_free);
}
/* clean up the buffers */
while (!list_empty(&ctx->writelist_free)) {
struct writelist *wl;
Expand Down