linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] pthread_setschedparam.3: Invalid free() in example code
@ 2014-11-29 17:41 Simon Newton
       [not found] ` <CAPQm1=PpBDnu9jW=0zuYF5X853F1HHomn3Po9vLMZ78LHq=thg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Newton @ 2014-11-29 17:41 UTC (permalink / raw)
  To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA

The example program will crash if -A is used, since attr is uninitialized.

$ ./a.out  -A
*** Error in `./a.out': free(): invalid pointer: 0xb779c3c4 ***
Aborted (core dumped)



diff --git a/man3/pthread_setschedparam.3 b/man3/pthread_setschedparam.3
index 971bc0c..36b00bd 100644
--- a/man3/pthread_setschedparam.3
+++ b/man3/pthread_setschedparam.3
@@ -424,9 +424,11 @@ main(int argc, char *argv[])

     /* Destroy unneeded thread attributes object */

-    s = pthread_attr_destroy(&attr);
-    if (s != 0)
-        handle_error_en(s, "pthread_attr_destroy");
+    if (!use_null_attrib) {
+      s = pthread_attr_destroy(&attr);
+      if (s != 0)
+          handle_error_en(s, "pthread_attr_destroy");
+    }

     s = pthread_join(thread, NULL);
     if (s != 0)
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [patch] pthread_setschedparam.3: Invalid free() in example code
       [not found] ` <CAPQm1=PpBDnu9jW=0zuYF5X853F1HHomn3Po9vLMZ78LHq=thg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-12-23 15:31   ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Kerrisk (man-pages) @ 2014-12-23 15:31 UTC (permalink / raw)
  To: Simon Newton
  Cc: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w,
	linux-man-u79uwXL29TY76Z2rM5mHXA

Hello Simon,

On 11/29/2014 06:41 PM, Simon Newton wrote:
> The example program will crash if -A is used, since attr is uninitialized.
> 
> $ ./a.out  -A
> *** Error in `./a.out': free(): invalid pointer: 0xb779c3c4 ***
> Aborted (core dumped)
> 
> 
> 
> diff --git a/man3/pthread_setschedparam.3 b/man3/pthread_setschedparam.3
> index 971bc0c..36b00bd 100644
> --- a/man3/pthread_setschedparam.3
> +++ b/man3/pthread_setschedparam.3
> @@ -424,9 +424,11 @@ main(int argc, char *argv[])
> 
>      /* Destroy unneeded thread attributes object */
> 
> -    s = pthread_attr_destroy(&attr);
> -    if (s != 0)
> -        handle_error_en(s, "pthread_attr_destroy");
> +    if (!use_null_attrib) {
> +      s = pthread_attr_destroy(&attr);
> +      if (s != 0)
> +          handle_error_en(s, "pthread_attr_destroy");
> +    }
> 
>      s = pthread_join(thread, NULL);
>      if (s != 0)

Thanks! Applied.

Cheers,

Michael




-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-12-23 15:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-29 17:41 [patch] pthread_setschedparam.3: Invalid free() in example code Simon Newton
     [not found] ` <CAPQm1=PpBDnu9jW=0zuYF5X853F1HHomn3Po9vLMZ78LHq=thg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-12-23 15:31   ` Michael Kerrisk (man-pages)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).