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

This commit is contained in:
Huong Nguyen 2024-03-15 11:07:51 +07:00
parent 70f611116d
commit 388cc303f9
2 changed files with 11 additions and 3 deletions

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;
}
/**

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;