@@ -825,15 +825,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
825825
826826 if ((xc = nng_msg_alloc (& msg , 0 ))) {
827827 NANO_FREE (buf );
828- R_Free (saio );
829- return mk_error_data (- xc );
828+ goto exitlevel1 ;
830829 }
830+
831831 if ((xc = nng_msg_append (msg , buf .buf , buf .cur )) ||
832832 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
833833 nng_msg_free (msg );
834834 NANO_FREE (buf );
835- R_Free (saio );
836- return mk_error_data (- xc );
835+ goto exitlevel1 ;
837836 }
838837
839838 nng_aio_set_msg (saio -> aio , msg );
@@ -854,16 +853,14 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
854853
855854 if ((xc = nng_msg_alloc (& msg , 0 ))) {
856855 NANO_FREE (buf );
857- R_Free (saio );
858- return mk_error_data (- xc );
856+ goto exitlevel1 ;
859857 }
860858
861859 if ((xc = nng_msg_append (msg , buf .buf , buf .cur )) ||
862860 (xc = nng_aio_alloc (& saio -> aio , saio_complete , saio ))) {
863861 nng_msg_free (msg );
864862 NANO_FREE (buf );
865- R_Free (saio );
866- return mk_error_data (- xc );
863+ goto exitlevel1 ;
867864 }
868865
869866 nng_aio_set_msg (saio -> aio , msg );
@@ -890,15 +887,13 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
890887
891888 if ((xc = nng_aio_alloc (& saio -> aio , isaio_complete , saio ))) {
892889 R_Free (saio -> data );
893- R_Free (saio );
894- return mk_error_data (- xc );
890+ goto exitlevel1 ;
895891 }
896892
897893 if ((xc = nng_aio_set_iov (saio -> aio , 1u , & iov ))) {
898894 nng_aio_free (saio -> aio );
899895 R_Free (saio -> data );
900- R_Free (saio );
901- return mk_error_data (- xc );
896+ goto exitlevel1 ;
902897 }
903898
904899 nng_aio_set_timeout (saio -> aio , dur );
@@ -926,6 +921,10 @@ SEXP rnng_send_aio(SEXP con, SEXP data, SEXP mode, SEXP timeout, SEXP clo) {
926921 UNPROTECT (3 );
927922 return env ;
928923
924+ exitlevel1 :
925+ R_Free (saio );
926+ return mk_error_data (- xc );
927+
929928}
930929
931930SEXP rnng_recv_aio (SEXP con , SEXP mode , SEXP timeout , SEXP bytes , SEXP clo ) {
@@ -942,10 +941,8 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
942941 raio -> type = RECVAIO ;
943942 raio -> mode = nano_matcharg (mode );
944943
945- if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio ))) {
946- R_Free (raio );
947- return mk_error_data (xc );
948- }
944+ if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio )))
945+ goto exitlevel1 ;
949946
950947 nng_aio_set_timeout (raio -> aio , dur );
951948 nng_recv_aio (* sock , raio -> aio );
@@ -959,10 +956,8 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
959956 raio -> type = RECVAIO ;
960957 raio -> mode = nano_matcharg (mode );
961958
962- if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio ))) {
963- R_Free (raio );
964- return mk_error_data (xc );
965- }
959+ if ((xc = nng_aio_alloc (& raio -> aio , raio_complete , raio )))
960+ goto exitlevel1 ;
966961
967962 nng_aio_set_timeout (raio -> aio , dur );
968963 nng_ctx_recv (* ctxp , raio -> aio );
@@ -982,18 +977,11 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
982977 iov .iov_len = xlen ;
983978 iov .iov_buf = raio -> data ;
984979
985- if ((xc = nng_aio_alloc (& raio -> aio , iraio_complete , raio ))) {
986- R_Free (raio -> data );
987- R_Free (raio );
988- return mk_error_data (xc );
989- }
980+ if ((xc = nng_aio_alloc (& raio -> aio , iraio_complete , raio )))
981+ goto exitlevel2 ;
990982
991- if ((xc = nng_aio_set_iov (raio -> aio , 1u , & iov ))) {
992- nng_aio_free (raio -> aio );
993- R_Free (raio -> data );
994- R_Free (raio );
995- return mk_error_data (xc );
996- }
983+ if ((xc = nng_aio_set_iov (raio -> aio , 1u , & iov )))
984+ goto exitlevel3 ;
997985
998986 nng_aio_set_timeout (raio -> aio , dur );
999987 nng_stream_recv (sp , raio -> aio );
@@ -1021,6 +1009,14 @@ SEXP rnng_recv_aio(SEXP con, SEXP mode, SEXP timeout, SEXP bytes, SEXP clo) {
10211009 UNPROTECT (3 );
10221010 return env ;
10231011
1012+ exitlevel3 :
1013+ nng_aio_free (raio -> aio );
1014+ exitlevel2 :
1015+ R_Free (raio -> data );
1016+ exitlevel1 :
1017+ R_Free (raio );
1018+ return mk_error_data (xc );
1019+
10241020}
10251021
10261022// ncurl aio -------------------------------------------------------------------
0 commit comments