This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Updated patch for Bug 13217 - thread apply all detach throws a SEGFAULT


>>>>> "Ali" == ali anwar <ali_anwar@codesourcery.com> writes:

Ali> +      /* Save a copy of the thread_list in case we execute detach
Ali> +         command.  */
Ali> +      tp_array =  xmalloc (sizeof (struct thread_info*) * tc);

Extra space after the "=".  Missing space before the "*" in the type
name.

Ali> +      ta_cleanup.tp_array = tp_array;
Ali> +      ta_cleanup.count = tc;
Ali> +
Ali> +      ALL_THREADS (tp)
Ali> +        {
Ali> +          tp_array[i] = tp;
Ali> +          tp->refcount++;
Ali> +          i++;
Ali> +        }
Ali> +      for (k = 0; k != i; k++)
Ali> +        if (thread_alive (tp_array[k]))
Ali> +          {
Ali> +            switch_to_thread (tp_array[k]->ptid);
Ali> +            printf_filtered (_("\nThread %d (%s):\n"),
Ali> +                             tp_array[k]->num, target_pid_to_str (inferior_ptid));
Ali> +            execute_command (cmd, from_tty);
Ali> +            strcpy (cmd, saved_cmd);        /* Restore exact command used
Ali> +                                               previously.  */
Ali> +           }
Ali> +
Ali> +      make_cleanup (xfree, tp_array);
Ali> +      make_cleanup (make_cleanup_thread_refcount, &ta_cleanup);

This installs the cleanups at the wrong point.
They must be installed before any potential exception is thrown.

That is, the xfree cleanup ought to be created just after initialization;
and the refcount cleanup ought to be created after the refcounts are
incremented.

Also, make_cleanup_thread_refcount is misnamed.
By convention, a "make_cleanup_" function creates a new cleanup.
The function that does the work of cleaning up is given a different name.

Tom


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]