Skip to content

Commit 927ac5e

Browse files
committed
Fix subtle bug introduced by debdfa5
1 parent b4d3b44 commit 927ac5e

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: nanonext
33
Title: NNG (Nanomsg Next Gen) Lightweight Messaging Library
4-
Version: 1.5.2.9020
4+
Version: 1.5.2.9021
55
Authors@R: c(
66
person("Charlie", "Gao", , "[email protected]", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0002-0750-061X")),

src/aio.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@ static SEXP mk_error_aio(const int xc, SEXP env) {
2020

2121
// aio completion callbacks ----------------------------------------------------
2222

23-
static inline void nano_list_free(nano_node *list) {
24-
25-
while (list != NULL) {
26-
nano_node *current = list;
27-
list = list->next;
28-
nano_aio *saio = (nano_aio *) current->data;
29-
nng_aio_free(saio->aio);
30-
if (saio->data != NULL)
31-
free(saio->data);
32-
free(saio);
33-
free(current);
34-
}
35-
36-
}
37-
3823
void nano_list_do(nano_list_op listop, nano_aio *saio) {
3924

4025
static nano_node *free_list = NULL;
@@ -47,7 +32,7 @@ void nano_list_do(nano_list_op listop, nano_aio *saio) {
4732
break;
4833
case FINALIZE:
4934
nng_mtx_lock(free_mtx);
50-
nano_list_free(free_list);
35+
nano_list_do(FREE, NULL);
5136
if (saio->mode == 0x1) {
5237
nng_mtx_unlock(free_mtx);
5338
nng_aio_free(saio->aio);
@@ -75,11 +60,23 @@ void nano_list_do(nano_list_op listop, nano_aio *saio) {
7560
case SHUTDOWN:
7661
if (free_mtx == NULL) break;
7762
nng_mtx_lock(free_mtx);
78-
nano_list_free(free_list);
63+
nano_list_do(FREE, NULL);
7964
nng_mtx_unlock(free_mtx);
8065
nng_mtx_free(free_mtx);
8166
free_mtx = NULL;
8267
break;
68+
case FREE: // must be entered under lock
69+
while (free_list != NULL) {
70+
nano_node *current = free_list;
71+
free_list = free_list->next;
72+
nano_aio *saio = (nano_aio *) current->data;
73+
nng_aio_free(saio->aio);
74+
if (saio->data != NULL)
75+
free(saio->data);
76+
free(saio);
77+
free(current);
78+
}
79+
break;
8380
}
8481

8582
}

src/nanonext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ typedef enum nano_list_op {
235235
INIT,
236236
FINALIZE,
237237
COMPLETE,
238+
FREE,
238239
SHUTDOWN
239240
} nano_list_op;
240241

0 commit comments

Comments
 (0)