Skip to content

Commit ee8c591

Browse files
committed
CDRIVER-756: This iov really should be const
We can't change the API now, so instead copy it and work on the copy to ensure we don't molest it
1 parent f8207fc commit ee8c591

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/mongoc/mongoc-socket.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,20 +1052,24 @@ _mongoc_socket_try_sendv (mongoc_socket_t *sock, /* IN */
10521052

10531053
ssize_t
10541054
mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
1055-
mongoc_iovec_t *iov, /* IN */
1055+
mongoc_iovec_t *in_iov, /* IN */
10561056
size_t iovcnt, /* IN */
10571057
int64_t expire_at) /* IN */
10581058
{
10591059
ssize_t ret = 0;
10601060
ssize_t sent;
10611061
size_t cur = 0;
1062+
mongoc_iovec_t *iov;
10621063

10631064
ENTRY;
10641065

10651066
bson_return_val_if_fail (sock, -1);
1066-
bson_return_val_if_fail (iov, -1);
1067+
bson_return_val_if_fail (in_iov, -1);
10671068
bson_return_val_if_fail (iovcnt, -1);
10681069

1070+
iov = bson_malloc(sizeof(*iov) * iovcnt);
1071+
memcpy(iov, in_iov, sizeof(*iov) * iovcnt);
1072+
10691073
for (;;) {
10701074
sent = _mongoc_socket_try_sendv (sock, &iov [cur], iovcnt - cur);
10711075

@@ -1076,7 +1080,8 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
10761080
*/
10771081
if (sent == -1) {
10781082
if (!_mongoc_socket_errno_is_again (sock)) {
1079-
RETURN (ret ? ret : -1);
1083+
ret = -1;
1084+
GOTO(CLEANUP);
10801085
}
10811086
}
10821087

@@ -1117,7 +1122,7 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
11171122
#else
11181123
errno = ETIMEDOUT;
11191124
#endif
1120-
RETURN (ret ? ret : -1);
1125+
GOTO(CLEANUP);
11211126
}
11221127

11231128
/*
@@ -1131,10 +1136,13 @@ mongoc_socket_sendv (mongoc_socket_t *sock, /* IN */
11311136
errno = ETIMEDOUT;
11321137
#endif
11331138
}
1134-
RETURN (ret ? ret : -1);
1139+
GOTO(CLEANUP);
11351140
}
11361141
}
11371142

1143+
CLEANUP:
1144+
bson_free(iov);
1145+
11381146
RETURN (ret);
11391147
}
11401148

0 commit comments

Comments
 (0)