Re: Program-assigned thread names on Windows

Jon Turney
2016-07-27T21:35:46Z

Doing a bit of testing with this patch...

On 26/07/2016 18:15, LRN wrote:
> + named_thread = find_thread_ptid (named_thread_ptid);

... it seems this may return NULL (e.g. if the thread we are naming was
short-lived and has already exited, or if the thread id was invalid) ...

> +
> + thread_name = NULL;
> + thread_name_len = target_read_string (thread_name_target, &thread_name, 1025, 0);
> + if (thread_name_len > 0 && thread_name != NULL)
> + {
> + thread_name[thread_name_len - 1] = '\0';
> + if (thread_name[0] != '\0')
> + {
> + xfree (named_thread->name);

... so this becomes a null dereference.

> + named_thread->name = thread_name;
> + }
> + else
> + {
> + xfree (thread_name);
> + }