Skip to content

Commit

Permalink
Fix bug in yarn ignition() that would read from freed memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
madler committed Apr 13, 2020
1 parent e1c77f9 commit 189866f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions yarn.c
Expand Up @@ -261,6 +261,10 @@ local void reenter(void *arg) {

// update the count of threads to be joined and alert join_all()
twist_(&(threads_lock), BY, +1, capsule->file, capsule->line);

// free the capsule resource, even if the thread is cancelled (though yarn
// doesn't use pthread_cancel() -- you never know)
my_free(capsule);
}

// All threads go through this routine. Just before a thread exits, it marks
Expand All @@ -275,9 +279,8 @@ local void *ignition(void *arg) {

// execute the requested function with argument
capsule->probe(capsule->payload);
my_free(capsule);

// mark this thread as done and let join_all() know
// mark this thread as done, letting join_all() know, and free capsule
pthread_cleanup_pop(1);

// exit thread
Expand Down

0 comments on commit 189866f

Please sign in to comment.