From patchwork Wed Apr 6 16:07:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Levin X-Patchwork-Id: 690111 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 p36G7vWU004754 for ; Wed, 6 Apr 2011 16:07:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754858Ab1DFQHy (ORCPT ); Wed, 6 Apr 2011 12:07:54 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:34141 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754293Ab1DFQHy (ORCPT ); Wed, 6 Apr 2011 12:07:54 -0400 Received: by ewy4 with SMTP id 4so504373ewy.19 for ; Wed, 06 Apr 2011 09:07:53 -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=5cIZUAjESsqJP39ijg+DUm50JcVji1fABY373PPCv5k=; b=Mf6zsSYDzi8JDXuaRVxUHDVSHlgB6Hv1MVtmnG3zw0ZXgYpZV543uuZgfsGrY4EM8P JaGhuqRlVKEbhOWRAdGlLGK+gAWpGlprMYI3IXyErig47/8zc8oqvTV8rIaaSut25kO7 GCxq4j0AbAPtYCMBTbV4LjFxo8x3BKolCIxkY= 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=dxvnZ030HarHHaQeaXRBf2Lsk+0HtX9jkL2QE8PkCEUFeENIC7Ii5pNiFlK669vw8Y PHAspoU9OV5+MtQ7bFNssBvio8TmQp1N3CFYucrPCdzIcBlUZcL7b+H1CjGBzs6NWEP6 De9AafjQeqyZT994xzFYPolMK7O50lt3mXlGs= Received: by 10.216.183.148 with SMTP id q20mr1173382wem.88.1302106072836; Wed, 06 Apr 2011 09:07:52 -0700 (PDT) Received: from [192.168.50.5] ([94.230.80.142]) by mx.google.com with ESMTPS id l5sm367820wej.8.2011.04.06.09.07.51 (version=SSLv3 cipher=OTHER); Wed, 06 Apr 2011 09:07:52 -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:07:43 +0300 Message-ID: <1302106063.2865.13.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:07:57 +0000 (UTC) Please ignore previous mail, Silly copy&paste mistake on the signed-off :) Following patch adds more cleanup code when exiting. Close disk image, free msrs array and destroy the timer fd. Signed-off-by: Sasha Levin --- 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);