multithreading - Issues with C pthreads and a malloc/seg fault error -
having problems c code (kinda new language). have following code: ..
rtspclient *clientinfo = (rtspclient*) malloc(sizeof(rtspclient)); if (!clientinfo) { printf("there wasn't enough memory fufill connection.\n"); continue; } clientinfo->socket = new_fd; pthread_create(&thread, null, handleclientconnection, (void *) clientinfo);
...
where rtspclient following
typedef struct { int socket; int session_id; playbacktimer* playback_timer; cvcapture* video; } rtspclient;
when try access video field in struct, getting seg faults. not allocating things correctly, wondering how can fix issue. need keep global variable clientinfo object allocated before thread started, or need allocate statically?
any appreciated.
rtspclient *clientinfo = (rtspclient*) malloc(sizeof(rtspclient));
creates memory clientinfo
structure. need allocate memory cvcapture* video;
, other pointers. (if do, please show more code how work allocated structure).
and sure meant continue
in case memory allocation failed? think should abort application if there not enough memory... or nothing work.
(and don't need cast return value of malloc
in c application)
Comments
Post a Comment