summaryrefslogtreecommitdiff
path: root/src/lib/dev.c
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2016-10-23 23:00:15 +0200
committerdimitri staessens <[email protected]>2016-10-23 23:00:15 +0200
commitb23e3024d12c28b01426cc37d5adf03f9c1bea88 (patch)
treee90bb2280b28d547c229529abe5f54bfc8837e34 /src/lib/dev.c
parenta4889a6f1e9f3d3c6822c403ac4fa544618a8c34 (diff)
downloadouroboros-b23e3024d12c28b01426cc37d5adf03f9c1bea88.tar.gz
ouroboros-b23e3024d12c28b01426cc37d5adf03f9c1bea88.zip
lib: Stabilise flow allocation
Deallocation was reverted to a synchronoous operation between the AP, IRMd and IPCP in order to avoid inconsistent states of the port_id. Fixes some memory leaks, particularly the shm_flow_set is now closed upon deallocation.
Diffstat (limited to 'src/lib/dev.c')
-rw-r--r--src/lib/dev.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 0a22cb12..94fbd394 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -283,7 +283,7 @@ void ap_fini()
pthread_rwlock_rdlock(&ai.flows_lock);
for (i = 0; i < AP_MAX_FLOWS; ++i) {
- if (ai.flows[i].tx_rb != NULL) {
+ if (ai.flows[i].rx_rb != NULL) {
ssize_t idx;
while ((idx = shm_rbuff_read(ai.flows[i].rx_rb)) >= 0)
shm_rdrbuff_remove(ai.rdrb, idx);
@@ -560,15 +560,14 @@ int flow_alloc_res(int fd)
if (ai.flows[fd].tx_rb == NULL) {
pthread_rwlock_unlock(&ai.flows_lock);
pthread_rwlock_unlock(&ai.data_lock);
- irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
ai.flows[fd].set = shm_flow_set_open(ai.flows[fd].api);
if (ai.flows[fd].set == NULL) {
+ shm_rbuff_close(ai.flows[fd].tx_rb);
pthread_rwlock_unlock(&ai.flows_lock);
pthread_rwlock_unlock(&ai.data_lock);
- irm_msg__free_unpacked(recv_msg, NULL);
return -1;
}
@@ -595,6 +594,7 @@ int flow_alloc_res(int fd)
int flow_dealloc(int fd)
{
irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg = NULL;
msg.code = IRM_MSG_CODE__IRM_FLOW_DEALLOC;
msg.has_port_id = true;
@@ -618,6 +618,24 @@ int flow_dealloc(int fd)
msg.port_id = ai.flows[fd].port_id;
+ pthread_rwlock_unlock(&ai.flows_lock);
+ pthread_rwlock_unlock(&ai.data_lock);
+
+ recv_msg = send_recv_irm_msg_b(&msg);
+ if (recv_msg == NULL) {
+ return -1;
+ }
+
+ if (!recv_msg->has_result) {
+ irm_msg__free_unpacked(recv_msg, NULL);
+ return -1;
+ }
+
+ irm_msg__free_unpacked(recv_msg, NULL);
+
+ pthread_rwlock_rdlock(&ai.data_lock);
+ pthread_rwlock_wrlock(&ai.flows_lock);
+
port_destroy(&ai.ports[msg.port_id]);
ai.flows[fd].port_id = -1;
@@ -627,6 +645,7 @@ int flow_dealloc(int fd)
ai.flows[fd].tx_rb = NULL;
ai.flows[fd].oflags = 0;
ai.flows[fd].api = -1;
+ shm_flow_set_close(ai.flows[fd].set);
if (ai.flows[fd].timeout != NULL) {
free(ai.flows[fd].timeout);
ai.flows[fd].timeout = NULL;
@@ -637,8 +656,6 @@ int flow_dealloc(int fd)
pthread_rwlock_unlock(&ai.flows_lock);
pthread_rwlock_unlock(&ai.data_lock);
- send_irm_msg(&msg);
-
return 0;
}