[libvirt] [PATCH] node_device_linux_sysfs.c: avoid opendir/fd leak on error path

Jim Meyering jim at meyering.net
Wed Jan 20 16:52:05 UTC 2010


This looks pretty clear.
It calls closedir upon successful return, but not in the error case.

>From 526a2bc2d87f0bf7a0c16a2a96316e5c1d5dae2e Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 20 Jan 2010 17:49:35 +0100
Subject: [PATCH] node_device_linux_sysfs.c: avoid opendir/fd leak on error path

* src/node_device/node_device_linux_sysfs.c(get_virtual_functions_linux):
Don't leak a DIR buffer and file descriptor on error path.
---
 src/node_device/node_device_linux_sysfs.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c
index ff7aaf0..e611e1a 100644
--- a/src/node_device/node_device_linux_sysfs.c
+++ b/src/node_device/node_device_linux_sysfs.c
@@ -2,7 +2,7 @@
  * node_device_hal_linuc.c: Linux specific code to gather device data
  * not available through HAL.
  *
- * Copyright (C) 2009 Red Hat, Inc.
+ * Copyright (C) 2009-2010 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -371,6 +371,8 @@ int get_virtual_functions_linux(const char *sysfs_path,
     ret = 0;

 out:
+    if (dir)
+        closedir(dir);
     VIR_FREE(device_link);
     return 0;
 }
--
1.6.6.516.gb72f




More information about the libvir-list mailing list