Mercurial > hg > freeDiameter
comparison freeDiameter/p_out.c @ 72:57ffd98dbe96
Fix race condition
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 01 Dec 2009 11:34:00 +0900 |
parents | 442f9cf1c704 |
children | eaa5205091d4 |
comparison
equal
deleted
inserted
replaced
71:cba30013d8f5 | 72:57ffd98dbe96 |
---|---|
63 fd_msg_dump_walk(FULL, *msg); | 63 fd_msg_dump_walk(FULL, *msg); |
64 } | 64 } |
65 | 65 |
66 /* Create the message buffer */ | 66 /* Create the message buffer */ |
67 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); | 67 CHECK_FCT(fd_msg_bufferize( *msg, &buf, &sz )); |
68 pthread_cleanup_push( free, buf ); | |
69 | |
70 /* Save a request before sending so that there is no race condition with the answer */ | |
71 if (msg_is_a_req) { | |
72 CHECK_FCT_DO( ret = fd_p_sr_store(srl, msg, &hdr->msg_hbhid), { free(buf); return ret; } ); | |
73 } | |
68 | 74 |
69 /* Send the message */ | 75 /* Send the message */ |
70 pthread_cleanup_push( free, buf ); | |
71 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz), { free(buf); return ret; } ); | 76 CHECK_FCT_DO( ret = fd_cnx_send(cnx, buf, sz), { free(buf); return ret; } ); |
72 pthread_cleanup_pop(1); | 77 pthread_cleanup_pop(1); |
73 | 78 |
74 /* Save a request */ | 79 /* Free remaining messages (i.e. answers) */ |
75 if (msg_is_a_req) { | |
76 CHECK_FCT_DO( fd_p_sr_store(srl, msg, &hdr->msg_hbhid), | |
77 { | |
78 fd_log_debug("The following request was sent successfully but not saved locally:\n" ); | |
79 fd_log_debug(" (as a result the matching answer will be discarded)\n" ); | |
80 fd_msg_dump_walk(NONE, *msg); | |
81 } ); | |
82 | |
83 } | |
84 | |
85 /* Free answers and unsaved requests */ | |
86 if (*msg) { | 80 if (*msg) { |
87 CHECK_FCT( fd_msg_free(*msg) ); | 81 CHECK_FCT( fd_msg_free(*msg) ); |
88 *msg = NULL; | 82 *msg = NULL; |
89 } | 83 } |
90 | 84 |