Skip to content

Commit 1cc12d3

Browse files
committed
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 <[email protected]>
1 parent bf5cb9f commit 1cc12d3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

storage.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,10 @@ struct rmtfd *storage_open(unsigned node, const char *path)
151151

152152
void storage_close(struct rmtfd *rmtfd)
153153
{
154-
close(rmtfd->fd);
155-
rmtfd->fd = -1;
154+
if (rmtfd->fd >= 0) {
155+
close(rmtfd->fd);
156+
rmtfd->fd = -1;
157+
}
156158

157159
free(rmtfd->shadow_buf);
158160
rmtfd->shadow_buf = NULL;
@@ -189,10 +191,8 @@ void storage_exit(void)
189191
{
190192
int i;
191193

192-
for (i = 0; i < MAX_CALLERS; i++) {
193-
if (rmtfds[i].fd >= 0)
194-
close(rmtfds[i].fd);
195-
}
194+
for (i = 0; i < MAX_CALLERS; i++)
195+
storage_close(&rmtfds[i]);
196196
}
197197

198198
ssize_t storage_pread(const struct rmtfd *rmtfd, void *buf, size_t nbyte, off_t offset)

0 commit comments

Comments
 (0)