smpp: Close the file descriptor when we can't accept the SMSC conn

When we failed to allocate the memory or failed to register the
fd we would have leaked the file descriptor. Close the fd and
avoid the leak.
This commit is contained in:
Holger Hans Peter Freyther
2013-07-14 08:59:32 +02:00
parent c962d45669
commit 1b624ba1f6

View File

@@ -867,8 +867,10 @@ static int link_accept_cb(struct smsc *smsc, int fd,
struct sockaddr_storage *s, socklen_t s_len) struct sockaddr_storage *s, socklen_t s_len)
{ {
struct osmo_esme *esme = talloc_zero(smsc, struct osmo_esme); struct osmo_esme *esme = talloc_zero(smsc, struct osmo_esme);
if (!esme) if (!esme) {
close(fd);
return -ENOMEM; return -ENOMEM;
}
smpp_esme_get(esme); smpp_esme_get(esme);
esme->own_seq_nr = rand(); esme->own_seq_nr = rand();
@@ -880,6 +882,7 @@ static int link_accept_cb(struct smsc *smsc, int fd,
esme->wqueue.bfd.when = BSC_FD_READ; esme->wqueue.bfd.when = BSC_FD_READ;
if (osmo_fd_register(&esme->wqueue.bfd) != 0) { if (osmo_fd_register(&esme->wqueue.bfd) != 0) {
close(fd);
talloc_free(esme); talloc_free(esme);
return -EIO; return -EIO;
} }