Do not attempt to clean up thread related structures in decompression failure conditions due to the indeterminate state of threads, letting the leaked memory to simply be freed on process exit.

This commit is contained in:
ckolivas 2026-02-13 10:28:37 +11:00
parent 2885060409
commit 96931e7019
3 changed files with 14 additions and 1 deletions

View file

@ -782,6 +782,12 @@ static void release_hashes(rzip_control *control)
static void clear_rulist(rzip_control *control)
{
/* If we're unable to safely clean up thread-related memory due to
* a failure in decompression, let the small memory leak be cleaned
* up by process exit */
if (unlikely(control->thread_count > 0)) {
return;
}
while (control->ruhead) {
struct runzip_node *node = control->ruhead;
struct stream_info *sinfo = node->sinfo;

View file

@ -31,6 +31,7 @@
#include <stdbool.h>
#include <stdarg.h>
#include <semaphore.h>
#include <stdatomic.h>
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
@ -467,6 +468,7 @@ struct rzip_control {
pthread_t *pthreads;
struct runzip_node *ruhead;
atomic_int thread_count;
};
struct uncomp_thread {

View file

@ -56,6 +56,7 @@
#endif
#include <inttypes.h>
#include <stdatomic.h>
/* LZMA C Wrapper */
#include "lzma/C/LzmaLib.h"
@ -124,8 +125,11 @@ static bool cond_broadcast(rzip_control *control, pthread_cond_t *cond)
bool create_pthread(rzip_control *control, pthread_t *thread, pthread_attr_t * attr,
void * (*start_routine)(void *), void *arg)
{
if (unlikely(pthread_create(thread, attr, start_routine, arg)))
atomic_fetch_add(&control->thread_count, 1);
if (unlikely(pthread_create(thread, attr, start_routine, arg))) {
atomic_fetch_sub(&control->thread_count, 1);
fatal_return(("Failed to pthread_create\n"), false);
}
return true;
}
@ -140,6 +144,7 @@ bool join_pthread(rzip_control *control, pthread_t th, void **thread_return)
{
if (pthread_join(th, thread_return))
fatal_return(("Failed to pthread_join\n"), false);
atomic_fetch_sub(&control->thread_count, 1);
return true;
}