r/linux_programming • u/promach • Jun 04 '18
forked processes finish sequence dilemma
/r/cpp_questions/comments/8oegn3/forked_processes_finish_sequence_dilemma/
2
Upvotes
r/linux_programming • u/promach • Jun 04 '18
View all comments
Show parent comment
1
u/[deleted] Jun 05 '18 edited Jun 05 '18
I'm afraid I don't have too much experience with multi-threading or race conditions.
The only other thing I can suggest is to refactor your code to fully utilize C++, and particularly modern C++. You have multiple memory leaks. For instance, you call
mallocin thergb2yuvfunction and return a pointer to astruct YUV_packet. You end up using them in the initialization ofuint8_t expected_Y,uint8_t expected_U, anduint8_t expected_Z, but you don't properlyfreethem. There is almost never a reason to usemalloc/freeinstead ofnew/delete, almost never a reason to usenew/deleteoutside of constructors/destructors (i.e., RAII), and since C++11, rarely a reason to not use smart pointers to avoid even these. In thergb2yuvfunction, there is really no reason to use any resource allocation. You should just adjustrgb2yuvto return astruct YUV_packet, not a pointer, and in the function, initialize it withoutmalloc. i.e.,YUV_packet yuv_result;.