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

View File

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