Skip to content

Commit

Permalink
block/linux-aio: fix memory and fd leak
Browse files Browse the repository at this point in the history
Hot unplugging -drive aio=native,file=test.img,format=raw images leaves
the Linux AIO event notifier and struct qemu_laio_state allocated.
Luckily nothing will use the event notifier after the BlockDriverState
has been closed so the handler function is never called.

It's still worth fixing this resource leak.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
stefanhaRH committed Jun 4, 2014
1 parent c2f3426 commit abd269b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions block/linux-aio.c
Expand Up @@ -212,3 +212,11 @@ void *laio_init(void)
g_free(s);
return NULL;
}

void laio_cleanup(void *s_)
{
struct qemu_laio_state *s = s_;

event_notifier_cleanup(&s->e);
g_free(s);
}
1 change: 1 addition & 0 deletions block/raw-aio.h
Expand Up @@ -34,6 +34,7 @@
/* linux-aio.c - Linux native implementation */
#ifdef CONFIG_LINUX_AIO
void *laio_init(void);
void laio_cleanup(void *s);
BlockDriverAIOCB *laio_submit(BlockDriverState *bs, void *aio_ctx, int fd,
int64_t sector_num, QEMUIOVector *qiov, int nb_sectors,
BlockDriverCompletionFunc *cb, void *opaque, int type);
Expand Down
5 changes: 5 additions & 0 deletions block/raw-posix.c
Expand Up @@ -1087,6 +1087,11 @@ static void raw_close(BlockDriverState *bs)

raw_detach_aio_context(bs);

#ifdef CONFIG_LINUX_AIO
if (s->use_aio) {
laio_cleanup(s->aio_ctx);
}
#endif
if (s->fd >= 0) {
qemu_close(s->fd);
s->fd = -1;
Expand Down

0 comments on commit abd269b

Please sign in to comment.