Plug memory leaks.
Found by: Coverity Prevent CID: 7052, 7053, 7054, 7055 MFC after: 3 days
This commit is contained in:
parent
fc066a6137
commit
6744284aec
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=209179
@ -96,6 +96,7 @@ metadata_read(struct hast_resource *res, bool openrw)
|
|||||||
rerrno = errno;
|
rerrno = errno;
|
||||||
pjdlog_errno(LOG_ERR,
|
pjdlog_errno(LOG_ERR,
|
||||||
"Unable to allocate memory to read metadata");
|
"Unable to allocate memory to read metadata");
|
||||||
|
ebuf_free(eb);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
buf = ebuf_data(eb, NULL);
|
buf = ebuf_data(eb, NULL);
|
||||||
@ -154,6 +155,7 @@ metadata_read(struct hast_resource *res, bool openrw)
|
|||||||
nv_free(nv);
|
nv_free(nv);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
nv_free(nv);
|
||||||
return (0);
|
return (0);
|
||||||
fail:
|
fail:
|
||||||
if (opened_here) {
|
if (opened_here) {
|
||||||
@ -172,6 +174,7 @@ metadata_write(struct hast_resource *res)
|
|||||||
unsigned char *buf, *ptr;
|
unsigned char *buf, *ptr;
|
||||||
size_t size;
|
size_t size;
|
||||||
ssize_t done;
|
ssize_t done;
|
||||||
|
int ret;
|
||||||
|
|
||||||
buf = calloc(1, METADATA_SIZE);
|
buf = calloc(1, METADATA_SIZE);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
@ -180,6 +183,8 @@ metadata_write(struct hast_resource *res)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
nv = nv_alloc();
|
nv = nv_alloc();
|
||||||
nv_add_string(nv, res->hr_name, "resource");
|
nv_add_string(nv, res->hr_name, "resource");
|
||||||
nv_add_uint64(nv, (uint64_t)res->hr_datasize, "datasize");
|
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");
|
nv_add_string(nv, role2str(res->hr_role), "prevrole");
|
||||||
if (nv_error(nv) != 0) {
|
if (nv_error(nv) != 0) {
|
||||||
pjdlog_error("Unable to create metadata.");
|
pjdlog_error("Unable to create metadata.");
|
||||||
goto fail;
|
goto end;
|
||||||
}
|
}
|
||||||
res->hr_previous_role = res->hr_role;
|
res->hr_previous_role = res->hr_role;
|
||||||
eb = nv_hton(nv);
|
eb = nv_hton(nv);
|
||||||
@ -211,12 +216,11 @@ metadata_write(struct hast_resource *res)
|
|||||||
done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0);
|
done = pwrite(res->hr_localfd, buf, METADATA_SIZE, 0);
|
||||||
if (done < 0 || done != METADATA_SIZE) {
|
if (done < 0 || done != METADATA_SIZE) {
|
||||||
pjdlog_errno(LOG_ERR, "Unable to write metadata");
|
pjdlog_errno(LOG_ERR, "Unable to write metadata");
|
||||||
goto fail;
|
goto end;
|
||||||
}
|
}
|
||||||
|
ret = 0;
|
||||||
return (0);
|
end:
|
||||||
fail:
|
|
||||||
free(buf);
|
free(buf);
|
||||||
nv_free(nv);
|
nv_free(nv);
|
||||||
return (-1);
|
return (ret);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user