c prog that take int x and pass it to thread to return x+10
i tried to free()mem i allocate in prog using malloc
// problem i get this error Aborted (core dumped)
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
void *fun(void *TX);
int main()
{
int x =50;
void *exitstat;
pthread_t thread1;
pthread_create(&thread1, NULL, fun, &x);
pthread_join(thread1, &exitstat);
int *result=(int *)exitstat;
printf("%d",*result);
// problem is here i get this error Aborted (core dumped)
//free(exitstat);
return 0;
}
void *fun(void *TX)
{
int *num = (int*)malloc(sizeof(int*)) ;
num=(int*)TX;
(*num)=(*num)+10;
//free(num); // can't free it here need to return num
return num;
}
note :
prog work fine (test on cygwin) if i remove free(exitstat);
but that lead to mem leak