[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 16/24] tools/xenstore: get_handle: Allocate struct before opening fd
Now we can also abolish the temporary local variable "fd" and simply use h->fd. This ordering is necessary to be able to call xentoolcore__register_active_handle sensibly. Signed-off-by: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx> Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx> --- tools/xenstore/xs.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/tools/xenstore/xs.c b/tools/xenstore/xs.c index 65cba86..7f85bb2 100644 --- a/tools/xenstore/xs.c +++ b/tools/xenstore/xs.c @@ -223,27 +223,26 @@ static struct xs_handle *get_handle(const char *connect_to) { struct stat buf; struct xs_handle *h = NULL; - int fd = -1, saved_errno; + int saved_errno; + + h = malloc(sizeof(*h)); + if (h == NULL) + goto err; + + memset(h, 0, sizeof(*h)); + h->fd = -1; if (stat(connect_to, &buf) != 0) goto err; if (S_ISSOCK(buf.st_mode)) - fd = get_socket(connect_to); + h->fd = get_socket(connect_to); else - fd = get_dev(connect_to); + h->fd = get_dev(connect_to); - if (fd == -1) + if (h->fd == -1) goto err; - h = malloc(sizeof(*h)); - if (h == NULL) - goto err; - - memset(h, 0, sizeof(*h)); - - h->fd = fd; - INIT_LIST_HEAD(&h->reply_list); INIT_LIST_HEAD(&h->watch_list); @@ -267,7 +266,10 @@ static struct xs_handle *get_handle(const char *connect_to) err: saved_errno = errno; - if (fd >= 0) close(fd); + if (h) { + if (h->fd >= 0) + close(h->fd); + } free(h); errno = saved_errno; -- 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |