Don't leak fd when manipulating the device via _getdev()

Close the file descriptor when done calling ioctl with a try-finally block so
it doesn't get leaked.

MFC after:	2 months
This commit is contained in:
Enji Cooper 2019-04-24 05:47:09 +00:00
parent 8b82def341
commit 56bf253633
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=346625

View File

@ -122,10 +122,12 @@ class CryptAEAD(dpkt.Packet):
CIOCCRYPTAEAD = 3225445229
def _getdev():
fd = os.open('/dev/crypto', os.O_RDWR)
buf = array.array('I', [0])
ioctl(fd, CRIOGET, buf, 1)
os.close(fd)
fd = os.open('/dev/crypto', os.O_RDWR)
try:
ioctl(fd, CRIOGET, buf, 1)
finally:
os.close(fd)
return buf[0]