From 4bb5ad281bc793428b9bd19483918812d2e64d66 Mon Sep 17 00:00:00 2001 From: Avi Kivity <avi@cloudius-systems.com> Date: Tue, 3 Dec 2013 16:57:50 +0200 Subject: [PATCH] file: close() outside destructor Once file::~file() is called, virtual functions no longer dispatch to the derived type (which has since been destroyed) but to the base type, which is uninteresting. Move the call to close() from the destructor to fdrop(). Signed-off-by: Avi Kivity <avi@cloudius-systems.com> --- fs/vfs/kern_descrip.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/vfs/kern_descrip.cc b/fs/vfs/kern_descrip.cc index 333184cc6..4133adffb 100644 --- a/fs/vfs/kern_descrip.cc +++ b/fs/vfs/kern_descrip.cc @@ -216,14 +216,6 @@ int fdrop(struct file *fp) if (__sync_fetch_and_sub(&fp->f_count, 1) != 1) return 0; - delete fp; - return 1; -} - -file::~file() -{ - auto fp = this; - /* We are about to free this file structure, but we still do things with it * so set the refcount to INT_MIN, fhold/fdrop may get called again * and we don't want to reach this point more than once. @@ -232,6 +224,14 @@ file::~file() fp->f_count = INT_MIN; fo_close(fp); + delete fp; + return 1; +} + +file::~file() +{ + auto fp = this; + poll_drain(fp); if (f_epolls) { for (auto ep : *f_epolls) { -- GitLab