/** * netproto_close(C): * Cancel all pending writes and any in-progress read, and free memory. */ int netproto_close(NETPROTO_CONNECTION * C) { int rc, rc2; /* If we were connecting, cancel that. */ if (C->cancel != NULL) rc = (C->cancel)(C->cookie); else rc = 0; /* Cancel pending writes. */ if (C->Q != NULL) { rc2 = network_writeq_cancel(C->Q); rc = rc ? rc : rc2; } /* Free the write queue. */ if (C->Q != NULL) network_writeq_free(C->Q); /* Cancel any in-progress read. */ if (C->fd != -1) { rc2 = network_deregister(C->fd, NETWORK_OP_READ); rc = rc ? rc : rc2; } /* Free cryptographic keys, if any exist. */ crypto_session_free(C->keys); /* Close the socket. */ while (C->fd != -1 && close(C->fd)) { if (errno == ECONNRESET) { /* * You can't dump me! I'm dumping you! We don't * care about the connection dying since we we're * done with it anyway. */ break; } if (errno != EINTR) { warnp("close()"); goto err1; } } /* Free the network protocol cookie. */ free(C); /* Return success or the first nonzero callback value. */ return (rc); err1: free(C); /* Failure! */ return (-1); }
static void crypto_session_end(JCR *jcr) { if (jcr->crypto.crypto_buf) { free_pool_memory(jcr->crypto.crypto_buf); jcr->crypto.crypto_buf = NULL; } if (jcr->crypto.pki_session) { crypto_session_free(jcr->crypto.pki_session); } if (jcr->crypto.pki_session_encoded) { free_pool_memory(jcr->crypto.pki_session_encoded); jcr->crypto.pki_session_encoded = NULL; } }