From 9c411c88280e71a0643f66d8566c73c36fca1647 Mon Sep 17 00:00:00 2001 From: Alexander Kharkov Date: Fri, 18 May 2018 04:52:06 +0000 Subject: [PATCH] Fix file descriptors leak which as result disk usage leak produced by wrong use of python tempfile.mkstemp Change-Id: Ia5e015c4d7a838f7e7701e078204e7e9d0d363bb Closes-Bug: 1771928 --- nova/virt/lxd/driver.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nova/virt/lxd/driver.py b/nova/virt/lxd/driver.py index 7cd6c20a..fb781f66 100644 --- a/nova/virt/lxd/driver.py +++ b/nova/virt/lxd/driver.py @@ -255,8 +255,8 @@ def _sync_glance_image_to_lxd(client, context, image_ref): raise try: - image_file = tempfile.mkstemp()[1] - manifest_file = tempfile.mkstemp()[1] + ifd, image_file = tempfile.mkstemp() + mfd, manifest_file = tempfile.mkstemp() image = IMAGE_API.get(context, image_ref) if image.get('disk_format') not in ACCEPTABLE_IMAGE_FORMATS: @@ -353,6 +353,8 @@ def _sync_glance_image_to_lxd(client, context, image_ref): image.add_alias(image_ref, '') finally: + os.close(ifd) + os.close(mfd) os.unlink(image_file) os.unlink(manifest_file)