Bug #1875 ยป 0001-osmo_stream_srv_fd_cb-don-t-leak-socket-FDs-on-error.patch
src/stream.c | ||
---|---|---|
394 | 394 |
static int osmo_stream_srv_fd_cb(struct osmo_fd *ofd, unsigned int what) |
395 | 395 |
{ |
396 | 396 |
int ret; |
397 |
int sock_fd; |
|
397 | 398 |
struct sockaddr_in sa; |
398 | 399 |
socklen_t sa_len = sizeof(sa); |
399 | 400 |
struct osmo_stream_srv_link *link = ofd->data; |
... | ... | |
406 | 407 |
} |
407 | 408 |
LOGP(DLINP, LOGL_DEBUG, "accept()ed new link from %s to port %u\n", |
408 | 409 |
inet_ntoa(sa.sin_addr), link->port); |
410 |
sock_fd = ret; |
|
409 | 411 | |
410 |
if (link->proto == IPPROTO_SCTP) |
|
411 |
sctp_sock_activate_events(ret); |
|
412 |
if (link->proto == IPPROTO_SCTP) { |
|
413 |
ret = sctp_sock_activate_events(sock_fd); |
|
414 |
if (ret < 0) |
|
415 |
goto error_close_socket; |
|
416 |
} |
|
412 | 417 | |
413 |
if (link->accept_cb) |
|
414 |
link->accept_cb(link, ret); |
|
418 |
if (!link->accept_cb) { |
|
419 |
ret = -ENOTSUP; |
|
420 |
goto error_close_socket; |
|
421 |
} |
|
415 | 422 | |
423 |
ret = link->accept_cb(link, sock_fd); |
|
424 |
if (ret) |
|
425 |
goto error_close_socket; |
|
416 | 426 |
return 0; |
427 | ||
428 |
error_close_socket: |
|
429 |
close(sock_fd); |
|
430 |
return ret; |
|
417 | 431 |
} |
418 | 432 | |
419 | 433 |
struct osmo_stream_srv_link *osmo_stream_srv_link_create(void *ctx) |