Fix the usage of realloc
http://ci.rvm.jp/results/trunk-repeat50@ruby-sp2-noble-docker/5420911 ``` /tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c: In function ‘reallocate_connection_attempt_fds’: /tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c:292:62: warning: pointer ‘fds’ may be used after ‘realloc’ [-Wuse-after-free] 292 | for (int i = current_capacity; i < new_capacity; i++) fds[i] = -1; | ^ /tmp/ruby/src/trunk-repeat50/ext/socket/ipsocket.c:288:9: note: call to ‘realloc’ here 288 | if (realloc(fds, new_capacity * sizeof(int)) == NULL) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ```
This commit is contained in:
parent
f20b6e5dbc
commit
d43f796292
@ -281,15 +281,18 @@ allocate_connection_attempt_fds(int additional_capacity)
|
||||
}
|
||||
|
||||
static int
|
||||
reallocate_connection_attempt_fds(int *fds, int current_capacity, int additional_capacity)
|
||||
reallocate_connection_attempt_fds(int **fds, int current_capacity, int additional_capacity)
|
||||
{
|
||||
int new_capacity = current_capacity + additional_capacity;
|
||||
int *new_fds;
|
||||
|
||||
if (realloc(fds, new_capacity * sizeof(int)) == NULL) {
|
||||
new_fds = realloc(*fds, new_capacity * sizeof(int));
|
||||
if (new_fds == NULL) {
|
||||
rb_syserr_fail(errno, "realloc(3)");
|
||||
}
|
||||
*fds = new_fds;
|
||||
|
||||
for (int i = current_capacity; i < new_capacity; i++) fds[i] = -1;
|
||||
for (int i = current_capacity; i < new_capacity; i++) (*fds)[i] = -1;
|
||||
return new_capacity;
|
||||
}
|
||||
|
||||
@ -845,7 +848,7 @@ init_fast_fallback_inetsock_internal(VALUE v)
|
||||
if (errno == EINPROGRESS) {
|
||||
if (current_capacity == arg->connection_attempt_fds_size) {
|
||||
current_capacity = reallocate_connection_attempt_fds(
|
||||
arg->connection_attempt_fds,
|
||||
&arg->connection_attempt_fds,
|
||||
current_capacity,
|
||||
additional_capacity
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user