Skip to content

Commit

Permalink
Stop double-free of query
Browse files Browse the repository at this point in the history
There is a chance that a query is executed by WordPress's WPDB before
the health checks plugin wrapper has been loaded. In this case the
previous query in WPDB would be freed twice.

This patch fixes this by allowing any previous query to be flushed.

Fixes #25
  • Loading branch information
LinuxJedi committed May 4, 2023
1 parent b5b5b57 commit 36f290b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions inc/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class MDB_DB extends wpdb
{
public $total_query_time = 0.0;
private $first_run = true;

public function loadFromParentObj($parentObj)
{
Expand All @@ -22,6 +23,13 @@ public function loadFromParentObj($parentObj)

public function query($query)
{
// This covers the case where WPDB is used before this plugin is loaded.
// It stops the attempt to clean up a query twice.
if ($this->first_run) {
$this->first_run = false;
$this->result = null;
parent::flush();
}
$this->timer_start();
$result = parent::query($query);
$this->total_query_time += $this->timer_stop();
Expand Down

0 comments on commit 36f290b

Please sign in to comment.