Close file descriptor to release memory
Resolves openbmc/openbmc#1718
Change-Id: Ie3020e38682cd0195202f6b3eedbb0f4907fa666
Signed-off-by: Leonel Gonzalez <lgonzalez@us.ibm.com>
diff --git a/module/obmc/wsgi/apps/rest_dbus.py b/module/obmc/wsgi/apps/rest_dbus.py
index 605956c..5cb1a56 100644
--- a/module/obmc/wsgi/apps/rest_dbus.py
+++ b/module/obmc/wsgi/apps/rest_dbus.py
@@ -646,8 +646,15 @@
else:
filename = os.path.join(cls.file_loc, filename)
- with open(filename, "w") as fd:
- fd.write(request.body.read())
+ try:
+ file_contents = request.body.read()
+ request.body.close()
+ with open(filename, "w") as fd:
+ fd.write(file_contents)
+ except (IOError, ValueError), e:
+ abort(400, str(e))
+ except:
+ abort(400, "Unexpected Error")
class ImagePostHandler(RouteHandler):