threads: destroy pthread_attr_t before reuse

pthread_getattr_np re-initializes the attributes on use causing the
original pthread_attr_init to leak.  Destroy after use to prevent the
memory leak.

Ticket: 9032
pull/16213/head
Jason Ish 2 months ago committed by Victor Julien
parent e89b7644a8
commit 7a3d21bb2c

@ -1721,6 +1721,7 @@ TmEcode TmThreadSpawn(ThreadVars *tv)
} }
int rc = pthread_create(&tv->t, &attr, tv->tm_func, (void *)tv); int rc = pthread_create(&tv->t, &attr, tv->tm_func, (void *)tv);
pthread_attr_destroy(&attr);
if (rc) { if (rc) {
FatalError("Unable to create thread %s with pthread_create(): retval %d: %s", tv->name, rc, FatalError("Unable to create thread %s with pthread_create(): retval %d: %s", tv->name, rc,
strerror(errno)); strerror(errno));
@ -1733,6 +1734,7 @@ TmEcode TmThreadSpawn(ThreadVars *tv)
void *stack_addr; void *stack_addr;
pthread_attr_getstack(&attr, &stack_addr, &stack_size); pthread_attr_getstack(&attr, &stack_addr, &stack_size);
SCLogDebug("stack: %p; size %" PRIu64, stack_addr, (uintmax_t)stack_size); SCLogDebug("stack: %p; size %" PRIu64, stack_addr, (uintmax_t)stack_size);
pthread_attr_destroy(&attr);
} else { } else {
SCLogDebug("Unable to retrieve current stack-size for display; return code from " SCLogDebug("Unable to retrieve current stack-size for display; return code from "
"pthread_getattr_np() is %" PRId32, "pthread_getattr_np() is %" PRId32,

Loading…
Cancel
Save