From: vibi <vibi_sreenivasan@cms.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel][PATCH]: Fix in file qemu-sockets.c
Date: Wed, 6 May 2009 15:27:03 +0530 [thread overview]
Message-ID: <200905061527.03395.vibi_sreenivasan@cms.com> (raw)
1) Changed usage of malloc,free,strdup to qemu_malloc,qemu_free,qemu_strdup
2) Some coding style fixes (based on CODING_STYLE document)
3) Free struct addrinfo *res after failure of listen
Signed-off-by: vibi <vibi_sreenivasan@cms.com>
---
qemu-sockets.c | 62 ++++++++++++++++++++++++++++---------------------------
1 files changed, 32 insertions(+), 30 deletions(-)
diff --git a/qemu-sockets.c b/qemu-sockets.c
index 4111f82..bd49d29 100644
--- a/qemu-sockets.c
+++ b/qemu-sockets.c
@@ -161,21 +161,22 @@ int inet_listen(const char *str, char *ostr, int olen,
/* create socket + bind */
for (e = res; e != NULL; e = e->ai_next) {
- getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
- uaddr,INET6_ADDRSTRLEN,uport,32,
- NI_NUMERICHOST | NI_NUMERICSERV);
+ getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
+ uaddr,INET6_ADDRSTRLEN,uport,32,
+ NI_NUMERICHOST | NI_NUMERICSERV);
slisten = socket(e->ai_family, e->ai_socktype, e->ai_protocol);
- if (slisten < 0) {
+ if (slisten < 0) {
fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family), strerror(errno));
- continue;
- }
+ continue;
+ }
setsockopt(slisten,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on));
#ifdef IPV6_V6ONLY
if (e->ai_family == PF_INET6) {
/* listen on both ipv4 and ipv6 */
- setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off,sizeof(off));
+ setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off,
+ sizeof(off));
}
#endif
@@ -183,7 +184,7 @@ int inet_listen(const char *str, char *ostr, int olen,
if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {
if (sockets_debug)
fprintf(stderr,"%s: bind(%s,%s,%d): OK\n", __FUNCTION__,
- inet_strfamily(e->ai_family), uaddr, inet_getport(e));
+ inet_strfamily(e->ai_family), uaddr, inet_getport(e));
goto listen;
}
try_next = to && (inet_getport(e) <= to + port_offset);
@@ -207,6 +208,7 @@ listen:
if (listen(slisten,1) != 0) {
perror("listen");
closesocket(slisten);
+ freeaddrinfo(res);
return -1;
}
if (ostr) {
@@ -278,35 +280,35 @@ int inet_connect(const char *str, int socktype)
inet_print_addrinfo(__FUNCTION__, res);
for (e = res; e != NULL; e = e->ai_next) {
- if (getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
- uaddr,INET6_ADDRSTRLEN,uport,32,
- NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
+ if (getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
+ uaddr,INET6_ADDRSTRLEN,uport,32,
+ NI_NUMERICHOST | NI_NUMERICSERV) != 0) {
fprintf(stderr,"%s: getnameinfo: oops\n", __FUNCTION__);
- continue;
- }
+ continue;
+ }
sock = socket(e->ai_family, e->ai_socktype, e->ai_protocol);
- if (sock < 0) {
+ if (sock < 0) {
fprintf(stderr,"%s: socket(%s): %s\n", __FUNCTION__,
- inet_strfamily(e->ai_family), strerror(errno));
- continue;
- }
+ inet_strfamily(e->ai_family), strerror(errno));
+ continue;
+ }
setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on));
- /* connect to peer */
- if (connect(sock,e->ai_addr,e->ai_addrlen) < 0) {
+ /* connect to peer */
+ if (connect(sock,e->ai_addr,e->ai_addrlen) < 0) {
if (sockets_debug || NULL == e->ai_next)
fprintf(stderr, "%s: connect(%s,%s,%s,%s): %s\n", __FUNCTION__,
inet_strfamily(e->ai_family),
e->ai_canonname, uaddr, uport, strerror(errno));
closesocket(sock);
- continue;
- }
+ continue;
+ }
if (sockets_debug)
fprintf(stderr, "%s: connect(%s,%s,%s,%s): OK\n", __FUNCTION__,
inet_strfamily(e->ai_family),
e->ai_canonname, uaddr, uport);
freeaddrinfo(res);
- return sock;
+ return sock;
}
freeaddrinfo(res);
return -1;
@@ -322,17 +324,17 @@ int unix_listen(const char *str, char *ostr, int olen)
sock = socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- perror("socket(unix)");
- return -1;
+ perror("socket(unix)");
+ return -1;
}
opts = strchr(str, ',');
if (opts) {
len = opts - str;
- path = malloc(len+1);
+ path = qemu_malloc(len+1);
snprintf(path, len+1, "%.*s", len, str);
} else
- path = strdup(str);
+ path = qemu_strdup(str);
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;
@@ -365,11 +367,11 @@ int unix_listen(const char *str, char *ostr, int olen)
if (sockets_debug)
fprintf(stderr, "bind(unix:%s): OK\n", un.sun_path);
- free(path);
+ qemu_free(path);
return sock;
err:
- free(path);
+ qemu_free(path);
closesocket(sock);
return -1;
}
@@ -381,8 +383,8 @@ int unix_connect(const char *path)
sock = socket(PF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- perror("socket(unix)");
- return -1;
+ perror("socket(unix)");
+ return -1;
}
memset(&un, 0, sizeof(un));
--
1.6.0
next reply other threads:[~2009-05-06 9:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-06 9:57 vibi [this message]
2009-05-11 6:18 ` [Qemu-devel][PATCH]: Fix in file qemu-sockets.c Gerd Hoffmann
2009-05-11 7:01 ` vibisreenivasan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200905061527.03395.vibi_sreenivasan@cms.com \
--to=vibi_sreenivasan@cms.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).