This
29 if (pthread_create(&some_thread, NULL, &print_the_arguments, (void *)&args) != 0) {
should be
29 if (pthread_create(&some_thread, NULL, &print_the_arguments, (void *)args) != 0) {
when you are dynamically allocating args. Also, I'd advise
25 args->str = strdup("hello");
and skip the malloc
.
This code:
24 args->str = malloc(sizeof(char)*5);
25 args->str = "hello";
results in a memory leak, the memory from malloc is leaked. Perhaps you meant
24 args->str = malloc(sizeof(char)*5);
25 strcpy(args->str, "hello");
but that is also incorrect. The 5 should be a 6 to account for the null character
at the end of the string. strdup()
is a good shortcut for malloc
followed by strcpy
.