From patchwork Wed Apr 6 16:05:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 690101 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p36G5a1K003343 for ; Wed, 6 Apr 2011 16:05:36 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753676Ab1DFQFd (ORCPT ); Wed, 6 Apr 2011 12:05:33 -0400 Received: from mail-wy0-f174.google.com ([74.125.82.174]:38161 "EHLO mail-wy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752321Ab1DFQFc (ORCPT ); Wed, 6 Apr 2011 12:05:32 -0400 Received: by wya21 with SMTP id 21so1434323wya.19 for ; Wed, 06 Apr 2011 09:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:subject:from:to:cc:content-type:date:message-id :mime-version:x-mailer:content-transfer-encoding; bh=U8++RGmI0D4Su29ZlKWP6R2AiknH6OXcnXurKKftod0=; b=l4yJSenGqLiS+hFIi2f4FfXJEUDSBgOuRZLG5YPRWxGVxmhnEhzP7eV73KLmLI4kXV fxK3KhQoNgMuTkHpm7vN1D1+xJZk4itf7FSkko494xt53j7t9DCt/ATJ/w5iLnjQsMnX FcczGEMETPs+qwCOV/w7ZiuTe/KqOepScGi+o= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=okaeXEc4Snv+Eghr/vc8Ax6ebU5T9nf/9lgfrp09+MlLmnGlP85KxpgaislcqZ2oQj 9flHnjNhJ6Ma5rg0BsdhuWN6m8KHH+e9jrZLgZFqZG5sMY4glB44L36aYi0SEbm/Shet brci2a4tD/SJNWUOlbVI1cnTnVS4F/qhXaXMA= Received: by 10.216.144.86 with SMTP id m64mr1247392wej.32.1302105931502; Wed, 06 Apr 2011 09:05:31 -0700 (PDT) Received: from [192.168.50.5] ([94.230.80.142]) by mx.google.com with ESMTPS id t72sm365649wei.20.2011.04.06.09.05.30 (version=SSLv3 cipher=OTHER); Wed, 06 Apr 2011 09:05:31 -0700 (PDT) Subject: [PATCH] kvm tools: Free memory and FDs on exit From: Sasha Levin To: Pekka Enberg Cc: kvm Date: Wed, 06 Apr 2011 19:05:22 +0300 Message-ID: <1302105922.2865.11.camel@stimpy> Mime-Version: 1.0 X-Mailer: Evolution 2.32.2 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 06 Apr 2011 16:05:37 +0000 (UTC) Following patch adds more cleanup code when exiting. Close disk image, free msrs array and destroy the timer fd. Signed-off-by: Justin P. Mattock --- tools/kvm/include/kvm/kvm.h | 1 + tools/kvm/kvm.c | 14 ++++++++++++++ tools/kvm/main.c | 4 +++- 3 files changed, 18 insertions(+), 1 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h index a1af42f..a099307 100644 --- a/tools/kvm/include/kvm/kvm.h +++ b/tools/kvm/include/kvm/kvm.h @@ -43,6 +43,7 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename, void kvm__reset_vcpu(struct kvm *self); void kvm__setup_bios(struct kvm *self); void kvm__start_timer(struct kvm *self); +void kvm__stop_timer(struct kvm *self); void kvm__run(struct kvm *self); void kvm__irq_line(struct kvm *self, int irq, int level); bool kvm__emulate_io(struct kvm *self, uint16_t port, void *data, int direction, int size, uint32_t count); diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index 5067b8b..cdc1394 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -105,6 +105,11 @@ static struct kvm *kvm__new(void) void kvm__delete(struct kvm *self) { + kvm__stop_timer(self); + + if (self->msrs) + free(self->msrs); + free(self->ram_start); free(self); } @@ -612,6 +617,15 @@ void kvm__start_timer(struct kvm *self) die("timer_settime()"); } +void kvm__stop_timer(struct kvm *self) +{ + if (self->timerid) + if(timer_delete(self->timerid) < 0) + die("timer_delete()"); + + self->timerid = 0; +} + void kvm__run(struct kvm *self) { int err; diff --git a/tools/kvm/main.c b/tools/kvm/main.c index 1eeb311..d9c5321 100644 --- a/tools/kvm/main.c +++ b/tools/kvm/main.c @@ -220,7 +220,8 @@ int main(int argc, char *argv[]) } } exit_kvm: - kvm__delete(kvm); + disk_image__close(kvm->disk_image); + kvm__delete(kvm); return 0; @@ -230,6 +231,7 @@ panic_kvm: if (kvm->kvm_run->exit_reason == KVM_EXIT_UNKNOWN) fprintf(stderr, "KVM exit code: 0x%" PRIu64 "\n", kvm->kvm_run->hw.hardware_exit_reason); + disk_image__close(kvm->disk_image); kvm__show_registers(kvm); kvm__show_code(kvm); kvm__show_page_tables(kvm);