void hmesg_scrub(hmesg_t *mesg) { switch (mesg->type) { case HMESG_SESSION: if (mesg->status == HMESG_STATUS_REQ) hsession_fini(&mesg->data.session); break; case HMESG_JOIN: if (mesg->status == HMESG_STATUS_REQ || mesg->status == HMESG_STATUS_OK) { hsignature_fini(&mesg->data.join); } break; case HMESG_FETCH: if (mesg->status == HMESG_STATUS_OK) { hpoint_fini(&mesg->data.fetch.cand); hpoint_fini(&mesg->data.fetch.best); } break; case HMESG_REPORT: if (mesg->status == HMESG_STATUS_REQ) hpoint_fini(&mesg->data.fetch.cand); break; default: break; /* All other cases have no heap memory to release. */ } }
void harmony_fini(hdesc_t *hdesc) { if (hdesc) { hmesg_fini(&hdesc->mesg); hsession_fini(&hdesc->sess); hpoint_fini(&hdesc->curr); hpoint_fini(&hdesc->best); hperf_fini(hdesc->perf); if (hdesc->id && hdesc->id != default_id_buf) free(hdesc->id); free(hdesc->cmd); free(hdesc->ptr); free(hdesc); } }
int vertex_from_string(const char *str, hsignature_t *sig, vertex_t *result) { int retval = 0; hpoint_t pt = HPOINT_INITIALIZER; if (!str) { session_error("Cannot convert null string to vertex"); return -1; } if (hpoint_init(&pt, sig->range_len) != 0) { session_error("Error initializing temporary hpoint"); return -1; } if (hpoint_parse(&pt, sig, str) != 0) { session_error("Error parsing point string"); retval = -1; goto cleanup; } if (hpoint_align(&pt, sig) != 0) { session_error("Error aligning point to session signature"); retval = -1; goto cleanup; } if (vertex_from_hpoint(&pt, result) != 0) { session_error("Error converting point to vertex"); retval = -1; } cleanup: hpoint_fini(&pt); return retval; }