probe_t * probe_dup(const probe_t * probe) { probe_t * ret; packet_t * packet; if (!(packet = packet_dup(probe->packet))) goto ERR_PACKET_DUP; if (!(ret = probe_wrap_packet(packet))) goto ERR_PROBE_WRAP_PACKET; // if (!(ret->bitfield = bitfield_dup(probe->bitfield))) goto ERR_BITFIELD_DUP; ret->sending_time = probe->sending_time; ret->queueing_time = probe->queueing_time; ret->recv_time = probe->recv_time; ret->caller = probe->caller; #ifdef USE_SCHEDULING ret->delay = probe->delay ? field_dup(probe->delay): NULL; #endif return ret; /* ERR_BITFIELD_DUP: probe_free(ret); packet = NULL; */ ERR_PROBE_WRAP_PACKET: if (packet) packet_free(packet); ERR_PACKET_DUP: return NULL; }
bool network_process_recvq(network_t * network) { probe_t * probe, * reply; packet_t * packet; probe_reply_t * probe_reply; // Pop the packet from the queue if (!(packet = queue_pop_element(network->recvq, NULL))) { goto ERR_PACKET_POP; } // Transform the reply into a probe_t instance if(!(reply = probe_wrap_packet(packet))) { goto ERR_PROBE_WRAP_PACKET; } probe_set_recv_time(reply, get_timestamp()); if (network->is_verbose) { printf("Got reply:\n"); probe_dump(reply); } // Find the probe corresponding to this reply // The corresponding pointer (if any) is removed from network->probes if (!(probe = network_get_matching_probe(network, reply))) { goto ERR_PROBE_DISCARDED; } // Build a pair made of the probe and its corresponding reply if (!(probe_reply = probe_reply_create())) { goto ERR_PROBE_REPLY_CREATE; } // We're pass to the upper layer the probe and the reply to the upper layer. probe_reply_set_probe(probe_reply, probe); probe_reply_set_reply(probe_reply, reply); // Notify the instance which has build the probe that we've got the corresponding reply // TODO this provokes a double free: //pt_throw(NULL, probe->caller, event_create(PROBE_REPLY, probe_reply, NULL, (ELEMENT_FREE) probe_reply_free)); pt_throw(NULL, probe->caller, event_create(PROBE_REPLY, probe_reply, NULL, NULL)); // TODO probe_reply_free frees only the reply but probe_reply_deep_free cannot be used as other things may have references to its contents. return true; ERR_PROBE_REPLY_CREATE: ERR_PROBE_DISCARDED: probe_free(reply); ERR_PROBE_WRAP_PACKET: //packet_free(packet); TODO provoke segfault in case of stars ERR_PACKET_POP: return false; }