storage: Use storage_close() to free up resources on exit

Use storage_close() to free up the shadow buffers as well, to avoid any
lingering allocations.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
This commit is contained in:
Bjorn Andersson 2020-12-07 08:43:18 -08:00
parent bf5cb9faf2
commit 1cc12d3dc1

View File

@ -151,8 +151,10 @@ found:
void storage_close(struct rmtfd *rmtfd) void storage_close(struct rmtfd *rmtfd)
{ {
close(rmtfd->fd); if (rmtfd->fd >= 0) {
rmtfd->fd = -1; close(rmtfd->fd);
rmtfd->fd = -1;
}
free(rmtfd->shadow_buf); free(rmtfd->shadow_buf);
rmtfd->shadow_buf = NULL; rmtfd->shadow_buf = NULL;
@ -189,10 +191,8 @@ void storage_exit(void)
{ {
int i; int i;
for (i = 0; i < MAX_CALLERS; i++) { for (i = 0; i < MAX_CALLERS; i++)
if (rmtfds[i].fd >= 0) storage_close(&rmtfds[i]);
close(rmtfds[i].fd);
}
} }
ssize_t storage_pread(const struct rmtfd *rmtfd, void *buf, size_t nbyte, off_t offset) ssize_t storage_pread(const struct rmtfd *rmtfd, void *buf, size_t nbyte, off_t offset)