diff options
author | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-06-12 11:38:31 +0100 |
---|---|---|
committer | kfraser@localhost.localdomain <kfraser@localhost.localdomain> | 2007-06-12 11:38:31 +0100 |
commit | ff2fc71eda783205e4eca61af1b60138251439cd (patch) | |
tree | e479c724179300c117c36074d2ed0b3e7f4c8215 /tools/blktap/lib | |
parent | ab053a8b3369584cb18c4aa2473cf88f56b0294f (diff) | |
download | xen-ff2fc71eda783205e4eca61af1b60138251439cd.tar.gz xen-ff2fc71eda783205e4eca61af1b60138251439cd.tar.bz2 xen-ff2fc71eda783205e4eca61af1b60138251439cd.zip |
tools: warn_unused_result build fixes.
Note that some of the existing error checking for asprintf was wrong
for Linux. asprintf in glibc returns -1 on error, but leaves the
pointer uninitialized. Only the BSDs zero out the pointer on error.
Also, while fixing these warnings I saw several error paths that were
incorrect. This patch minimally fixes the warn_unused_result; more
complete error path cleanup will be a later patch.
Signed-off-by: Charles Coffing <ccoffing@novell.com>
Diffstat (limited to 'tools/blktap/lib')
-rw-r--r-- | tools/blktap/lib/xenbus.c | 6 | ||||
-rw-r--r-- | tools/blktap/lib/xs_api.c | 45 |
2 files changed, 24 insertions, 27 deletions
diff --git a/tools/blktap/lib/xenbus.c b/tools/blktap/lib/xenbus.c index fb36e748fe..53a3338f1e 100644 --- a/tools/blktap/lib/xenbus.c +++ b/tools/blktap/lib/xenbus.c @@ -360,8 +360,7 @@ int add_blockdevice_probe_watch(struct xs_handle *h, const char *domid) char *path; struct xenbus_watch *vbd_watch; - asprintf(&path, "/local/domain/%s/backend/tap", domid); - if (path == NULL) + if (asprintf(&path, "/local/domain/%s/backend/tap", domid) == -1) return -ENOMEM; vbd_watch = (struct xenbus_watch *)malloc(sizeof(struct xenbus_watch)); @@ -399,8 +398,7 @@ int watch_for_domid(struct xs_handle *h) struct xenbus_watch *domid_watch; char *path = NULL; - asprintf(&path, "/local/domain"); - if (path == NULL) + if (asprintf(&path, "/local/domain") == -1) return -ENOMEM; domid_watch = malloc(sizeof(struct xenbus_watch)); diff --git a/tools/blktap/lib/xs_api.c b/tools/blktap/lib/xs_api.c index 539d0e3c51..783b4ce3b3 100644 --- a/tools/blktap/lib/xs_api.c +++ b/tools/blktap/lib/xs_api.c @@ -126,10 +126,12 @@ int xs_printf(struct xs_handle *h, const char *dir, const char *node, ret = vasprintf(&buf, fmt, ap); va_end(ap); - asprintf(&path, "%s/%s", dir, node); - - if ((path == NULL) || (buf == NULL)) - return 0; + if (ret == -1) + return ENOMEM; + if (asprintf(&path, "%s/%s", dir, node) == -1) { + free(buf); + return ENOMEM; + } ret = xs_write(h, XBT_NULL, path, buf, strlen(buf)+1); @@ -180,10 +182,11 @@ char *get_dom_domid(struct xs_handle *h) e = xs_directory(h, xth, "/local/domain", &num); if (e == NULL) - return NULL; + goto done; for (i = 0; (i < num) && (domid == NULL); i++) { - asprintf(&path, "/local/domain/%s/name", e[i]); + if (asprintf(&path, "/local/domain/%s/name", e[i]) == -1) + break; val = xs_read(h, xth, path, &len); free(path); if (val == NULL) @@ -191,29 +194,31 @@ char *get_dom_domid(struct xs_handle *h) if (strcmp(val, DOMNAME) == 0) { /* match! */ - asprintf(&path, "/local/domain/%s/domid", e[i]); + if (asprintf(&path, "/local/domain/%s/domid", e[i]) == -1) { + free(val); + break; + } domid = xs_read(h, xth, path, &len); free(path); } free(val); } +done: xs_transaction_end(h, xth, 0); - - free(e); + if (e) + free(e); return domid; } int convert_dev_name_to_num(char *name) { - char *p_sd, *p_hd, *p_xvd, *p_plx, *p, *alpha,*ptr; + char *p, *ptr; int majors[10] = {3,22,33,34,56,57,88,89,90,91}; int maj,i,ret = 0; - - asprintf(&p_sd,"/dev/sd"); - asprintf(&p_hd,"/dev/hd"); - asprintf(&p_xvd,"/dev/xvd"); - asprintf(&p_plx,"plx"); - asprintf(&alpha,"abcdefghijklmnop"); - + char *p_sd = "/dev/sd"; + char *p_hd = "/dev/hd"; + char *p_xvd = "/dev/xvd"; + char *p_plx = "plx"; + char *alpha = "abcdefghijklmnop"; if (strstr(name, p_sd) != NULL) { p = name + strlen(p_sd); @@ -251,12 +256,6 @@ int convert_dev_name_to_num(char *name) { ret = BASE_DEV_VAL; } - free(p_sd); - free(p_hd); - free(p_xvd); - free(p_plx); - free(alpha); - return ret; } |