diff options
author | pjd <pjd@FreeBSD.org> | 2010-06-14 21:25:20 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2010-06-14 21:25:20 +0000 |
commit | ccd077e2698673b6a3dda6232f82f1a4b5c0478a (patch) | |
tree | ae83b900387ba4249de9e8f42c99632d6a924bb2 /sbin | |
parent | 9afd287a77d209e55688822292e8df6437e69c63 (diff) | |
download | FreeBSD-src-ccd077e2698673b6a3dda6232f82f1a4b5c0478a.zip FreeBSD-src-ccd077e2698673b6a3dda6232f82f1a4b5c0478a.tar.gz |
Plug memory leaks.
Found by: Coverity Prevent
CID: 7052, 7053, 7054, 7055
MFC after: 3 days
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/hastd/metadata.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/sbin/hastd/metadata.c b/sbin/hastd/metadata.c index 7a138e8..de21b53 100644 --- a/sbin/hastd/metadata.c +++ b/sbin/hastd/metadata.c @@ -96,6 +96,7 @@ metadata_read(struct hast_resource *res, bool openrw) rerrno = errno; pjdlog_errno(LOG_ERR, "Unable to allocate memory to read metadata"); + ebuf_free(eb); goto fail; } buf = ebuf_data(eb, NULL); @@ -154,6 +155,7 @@ metadata_read(struct hast_resource *res, bool openrw) nv_free(nv); goto fail; } + nv_free(nv); return (0); fail: if (opened_here) { @@ -172,6 +174,7 @@ metadata_write(struct hast_resource *res) unsigned char *buf, *ptr; size_t size; ssize_t done; + int ret; buf = calloc(1, METADATA_SIZE); if (buf == NULL) { @@ -180,6 +183,8 @@ metadata_write(struct hast_resource *res) return (-1); } + ret = -1; + nv = nv_alloc(); nv_add_string(nv, res->hr_name, "resource"); nv_add_uint64(nv, (uint64_t)res->hr_datasize, "datasize"); @@ -199,7 +204,7 @@ metadata_write(struct hast_resource *res) nv_add_string(nv, role2str(res->hr_role), "prevrole"); if (nv_error(nv) != 0) { pjdlog_error("Unable to create metadata."); - goto fail; + goto end; } res->hr_previous_role = res->hr_role; eb = nv_hton(nv); @@ -211,12 +216,11 @@ metadata_write(struct hast_resource *res) done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0); if (done < 0 || done != METADATA_SIZE) { pjdlog_errno(LOG_ERR, "Unable to write metadata"); - goto fail; + goto end; } - - return (0); -fail: + ret = 0; +end: free(buf); nv_free(nv); - return (-1); + return (ret); } |