Skip to content

Commit 70ee8dc

Browse files
committed
BUG29417117: Close file in handle load data infile
1 parent 9f2d834 commit 70ee8dc

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

lib/mysql/connector/connection.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,8 @@ def _handle_load_data_infile(self, filename):
435435
"""Handle a LOAD DATA INFILE LOCAL request"""
436436
try:
437437
data_file = open(filename, 'rb')
438+
return self._handle_ok(self._send_data(data_file,
439+
send_empty_packet=True))
438440
except IOError:
439441
# Send a empty packet to cancel the operation
440442
try:
@@ -444,9 +446,11 @@ def _handle_load_data_infile(self, filename):
444446
"MySQL Connection not available.")
445447
raise errors.InterfaceError(
446448
"File '{0}' could not be read".format(filename))
447-
448-
return self._handle_ok(self._send_data(data_file,
449-
send_empty_packet=True))
449+
finally:
450+
try:
451+
data_file.close()
452+
except (IOError, NameError):
453+
pass
450454

451455
def _handle_result(self, packet):
452456
"""Handle a MySQL Result

0 commit comments

Comments
 (0)