diff options
author | Руслан Ижбулатов <lrn1986@gmail.com> | 2017-02-25 12:57:37 +0000 |
---|---|---|
committer | Руслан Ижбулатов <lrn1986@gmail.com> | 2017-02-25 21:04:00 +0000 |
commit | 903c035f7948d1c216d2d85a68458572b0b17e36 (patch) | |
tree | 5f1c83cbd773c8d2f9964131a036cb3b5b40b807 /src | |
parent | 320460014899596bd93f17cd8e968b393e8e5a85 (diff) | |
download | gnunet-903c035f7948d1c216d2d85a68458572b0b17e36.tar.gz gnunet-903c035f7948d1c216d2d85a68458572b0b17e36.zip |
W32: Fix msg allocation in gns helper service
The code was hacky, and GCC warned about variables being used without
initialization. Turns out, it was much worse.
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/gnunet-gns-helper-service-w32.c | 50 |
1 files changed, 13 insertions, 37 deletions
diff --git a/src/gns/gnunet-gns-helper-service-w32.c b/src/gns/gnunet-gns-helper-service-w32.c index 33de2aab6..a59cc5981 100644 --- a/src/gns/gnunet-gns-helper-service-w32.c +++ b/src/gns/gnunet-gns-helper-service-w32.c | |||
@@ -154,27 +154,6 @@ do_shutdown (void *cls) | |||
154 | } | 154 | } |
155 | 155 | ||
156 | 156 | ||
157 | /** | ||
158 | * Transmit the given message to the client. | ||
159 | * | ||
160 | * @param client target of the message | ||
161 | * @param msg message to transmit, will be freed! | ||
162 | */ | ||
163 | static void | ||
164 | transmit (struct GNUNET_SERVICE_Client *client, | ||
165 | struct GNUNET_MessageHeader *msg) | ||
166 | { | ||
167 | struct GNUNET_MQ_Handle *mq = GNUNET_SERVICE_client_get_mq (client); | ||
168 | struct GNUNET_MQ_Envelope *env; | ||
169 | |||
170 | /* NOTE: small hack here, should have constructed and | ||
171 | passed an 'env' in the first place... */ | ||
172 | env = GNUNET_MQ_msg_copy (msg); | ||
173 | GNUNET_MQ_send (mq, | ||
174 | env); | ||
175 | } | ||
176 | |||
177 | |||
178 | #define MarshallPtr(ptr, base, type) \ | 157 | #define MarshallPtr(ptr, base, type) \ |
179 | if (ptr) \ | 158 | if (ptr) \ |
180 | ptr = (type *) ((char *) ptr - (char *) base) | 159 | ptr = (type *) ((char *) ptr - (char *) base) |
@@ -222,7 +201,9 @@ process_lookup_result (void *cls, | |||
222 | struct request *rq = cls; | 201 | struct request *rq = cls; |
223 | int i, j, csanum; | 202 | int i, j, csanum; |
224 | struct GNUNET_W32RESOLVER_GetMessage *msg; | 203 | struct GNUNET_W32RESOLVER_GetMessage *msg; |
204 | struct GNUNET_MQ_Envelope *msg_env; | ||
225 | struct GNUNET_MessageHeader *msgend; | 205 | struct GNUNET_MessageHeader *msgend; |
206 | struct GNUNET_MQ_Envelope *msgend_env; | ||
226 | WSAQUERYSETW *qs; | 207 | WSAQUERYSETW *qs; |
227 | size_t size; | 208 | size_t size; |
228 | size_t size_recalc; | 209 | size_t size_recalc; |
@@ -239,11 +220,9 @@ process_lookup_result (void *cls, | |||
239 | 220 | ||
240 | if (0 == rd_count) | 221 | if (0 == rd_count) |
241 | { | 222 | { |
242 | msg = GNUNET_new (struct GNUNET_MessageHeader); | 223 | msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); |
243 | msg->header.size = htons (sizeof (struct GNUNET_MessageHeader)); | 224 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client), |
244 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | 225 | msgend_env); |
245 | transmit (rq->client, | ||
246 | &msg->header); | ||
247 | GNUNET_CONTAINER_DLL_remove (rq_head, | 226 | GNUNET_CONTAINER_DLL_remove (rq_head, |
248 | rq_tail, | 227 | rq_tail, |
249 | rq); | 228 | rq); |
@@ -304,9 +283,9 @@ process_lookup_result (void *cls, | |||
304 | size += blobsize; | 283 | size += blobsize; |
305 | } | 284 | } |
306 | size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW); | 285 | size_recalc = sizeof (struct GNUNET_W32RESOLVER_GetMessage) + sizeof (WSAQUERYSETW); |
307 | msg = GNUNET_malloc (size); | 286 | msg_env = GNUNET_MQ_msg_extra (msg, |
308 | msg->header.size = htons (size - sizeof (struct GNUNET_MessageHeader)); | 287 | size - sizeof (struct GNUNET_MessageHeader), |
309 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | 288 | GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); |
310 | msg->af = htonl (rq->af); | 289 | msg->af = htonl (rq->af); |
311 | msg->sc_data1 = htonl (rq->sc.Data1); | 290 | msg->sc_data1 = htonl (rq->sc.Data1); |
312 | msg->sc_data2 = htons (rq->sc.Data2); | 291 | msg->sc_data2 = htons (rq->sc.Data2); |
@@ -465,10 +444,7 @@ process_lookup_result (void *cls, | |||
465 | } | 444 | } |
466 | he->h_addr_list[j] = NULL; | 445 | he->h_addr_list[j] = NULL; |
467 | } | 446 | } |
468 | msgend = GNUNET_new (struct GNUNET_MessageHeader); | 447 | msgend_env = GNUNET_MQ_msg (msgend, GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); |
469 | |||
470 | msgend->type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE); | ||
471 | msgend->size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
472 | 448 | ||
473 | if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg)) | 449 | if ((char *) ptr - (char *) msg != size || size_recalc != size || size_recalc != ((char *) ptr - (char *) msg)) |
474 | { | 450 | { |
@@ -479,10 +455,10 @@ process_lookup_result (void *cls, | |||
479 | size_recalc); | 455 | size_recalc); |
480 | } | 456 | } |
481 | MarshallWSAQUERYSETW (qs, &rq->sc); | 457 | MarshallWSAQUERYSETW (qs, &rq->sc); |
482 | transmit (rq->client, | 458 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client), |
483 | &msg->header); | 459 | msg_env); |
484 | transmit (rq->client, | 460 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (rq->client), |
485 | msgend); | 461 | msgend_env); |
486 | GNUNET_CONTAINER_DLL_remove (rq_head, | 462 | GNUNET_CONTAINER_DLL_remove (rq_head, |
487 | rq_tail, | 463 | rq_tail, |
488 | rq); | 464 | rq); |