ringbuf: fix cleanup operations

parent eafc1bb6
......@@ -20,9 +20,9 @@
int lxc_ringbuf_create(struct lxc_ringbuf *buf, size_t size)
{
__do_close int memfd = -EBADF;
char *tmp;
int ret;
int memfd = -1;
buf->size = size;
buf->r_off = 0;
......@@ -63,14 +63,10 @@ int lxc_ringbuf_create(struct lxc_ringbuf *buf, size_t size)
if (tmp == MAP_FAILED || tmp != (buf->addr + buf->size))
goto on_error;
close(memfd);
return 0;
on_error:
lxc_ringbuf_release(buf);
if (memfd >= 0)
close(memfd);
return -1;
}
......
......@@ -36,7 +36,8 @@ extern int lxc_ringbuf_read(struct lxc_ringbuf *buf, char *out, size_t *len);
static inline void lxc_ringbuf_release(struct lxc_ringbuf *buf)
{
munmap(buf->addr, buf->size * 2);
if (buf->addr)
munmap(buf->addr, buf->size * 2);
}
static inline void lxc_ringbuf_clear(struct lxc_ringbuf *buf)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment