MDL-81246 dml: Check the statement resource before freeing it

This commit is contained in:
Huong Nguyen
2024-03-15 11:19:43 +07:00
parent fde6c3c7ef
commit e70e73d9b7
2 changed files with 11 additions and 3 deletions
+3 -1
View File
@@ -680,9 +680,11 @@ class sqlsrv_native_moodle_database extends moodle_database {
* @return bool
*/
private function free_result($resource) {
if (!is_bool($resource)) { // true/false resources cannot be freed
if (!is_bool($resource) && is_resource($resource)) {
// We need to make sure that the statement resource is in the correct type before freeing it.
return sqlsrv_free_stmt($resource);
}
return false;
}
/**
+8 -2
View File
@@ -85,7 +85,10 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset {
return false;
}
if (!$row = sqlsrv_fetch_array($this->rsrc, SQLSRV_FETCH_ASSOC)) {
sqlsrv_free_stmt($this->rsrc);
if (is_resource($this->rsrc)) {
// We need to make sure that the statement resource is in the correct type before freeing it.
sqlsrv_free_stmt($this->rsrc);
}
$this->rsrc = null;
$this->unregister();
return false;
@@ -133,7 +136,10 @@ class sqlsrv_native_moodle_recordset extends moodle_recordset {
public function close() {
if ($this->rsrc) {
sqlsrv_free_stmt($this->rsrc);
if (is_resource($this->rsrc)) {
// We need to make sure that the statement resource is in the correct type before freeing it.
sqlsrv_free_stmt($this->rsrc);
}
$this->rsrc = null;
}
$this->current = null;