mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 15:30:42 +00:00
Fix two memory leaks in native parser. Now has no memory leaks :-)
This commit is contained in:
parent
901b79f8d3
commit
16909a2c42
|
@ -55,7 +55,7 @@ class AbuseFilterHooks {
|
|||
return true;
|
||||
}
|
||||
|
||||
function onAbortMove( $oldTitle, $newTitle, $user, &$error, $reason ) {
|
||||
public static function onAbortMove( $oldTitle, $newTitle, $user, &$error, $reason ) {
|
||||
$vars = array();
|
||||
|
||||
global $wgUser;
|
||||
|
@ -72,7 +72,7 @@ class AbuseFilterHooks {
|
|||
return $filter_result == '' || $filter_result === true;
|
||||
}
|
||||
|
||||
function onArticleDelete( &$article, &$user, &$reason, &$error ) {
|
||||
public static function onArticleDelete( &$article, &$user, &$reason, &$error ) {
|
||||
$vars = array();
|
||||
|
||||
global $wgUser;
|
||||
|
@ -88,7 +88,7 @@ class AbuseFilterHooks {
|
|||
return $filter_result == '' || $filter_result === true;
|
||||
}
|
||||
|
||||
function onAbortNewAccount( $user, &$message ) {
|
||||
public static function onAbortNewAccount( $user, &$message ) {
|
||||
wfLoadExtensionMessages( 'AbuseFilter' );
|
||||
if ($username == wfMsgForContent( 'abusefilter-blocker' )) {
|
||||
$message = wfMsg( 'abusefilter-accountreserved' );
|
||||
|
|
|
@ -442,7 +442,7 @@ class SpecialAbuseFilter extends SpecialPage {
|
|||
// Load the main row
|
||||
$row = $dbr->selectRow( 'abuse_filter', '*', array( 'af_id' => $id ), __METHOD__ );
|
||||
|
||||
if (!is_array($row))
|
||||
if (!$row->af_id)
|
||||
return array( new stdClass,array() );
|
||||
|
||||
// Load the actions
|
||||
|
|
Binary file not shown.
|
@ -6,7 +6,6 @@ void FilterEvaluator::reset() {
|
|||
this->tokens.clear();
|
||||
this->cur = AFPToken();
|
||||
this->pos = 0;
|
||||
this->code = "";
|
||||
this->forceResult = false;
|
||||
}
|
||||
|
||||
|
@ -21,7 +20,6 @@ void FilterEvaluator::setVars( map<string,AFPData> values ) {
|
|||
}
|
||||
|
||||
string FilterEvaluator::evaluateExpression( string code ) {
|
||||
this->code = code;
|
||||
this->pos = 0;
|
||||
|
||||
if (this->tokenCache.find(code) != this->tokenCache.end()) {
|
||||
|
@ -43,8 +41,9 @@ string FilterEvaluator::evaluateExpression( string code ) {
|
|||
return result.toString();
|
||||
}
|
||||
|
||||
// TODO: Merge these two functions
|
||||
|
||||
bool FilterEvaluator::evaluateFilter( string code ) {
|
||||
this->code = code;
|
||||
this->pos = 0;
|
||||
|
||||
if (this->tokenCache.find(code) != this->tokenCache.end()) {
|
||||
|
@ -320,7 +319,7 @@ void FilterEvaluator::doLevelFunction( AFPData* result ) {
|
|||
this->move(-1);
|
||||
do {
|
||||
this->move();
|
||||
AFPData r = new AFPData();
|
||||
AFPData r = AFPData();
|
||||
this->doLevelSet( &r );
|
||||
args.push_back( r );
|
||||
} while (this->cur.type == T_COMMA );
|
||||
|
|
|
@ -31,7 +31,6 @@ class FilterEvaluator {
|
|||
vector<AFPToken> tokens;
|
||||
map<string, vector<AFPToken> > tokenCache;
|
||||
unsigned int pos;
|
||||
string code;
|
||||
map<string,AFPData> vars;
|
||||
bool forceResult;
|
||||
};
|
||||
|
|
|
@ -127,7 +127,7 @@ AFPData callFunction( string name, vector<AFPData> args ) {
|
|||
string cacheKey;
|
||||
bool doCache = false;
|
||||
if (args.size() == 1) {
|
||||
doCache = true;
|
||||
doCache = true;
|
||||
cacheKey = name + args[0].toString();
|
||||
|
||||
if (functionResultCache.find(cacheKey) != functionResultCache.end()) {
|
||||
|
|
|
@ -144,7 +144,9 @@ AFPData::AFPData( AFPData old, unsigned int newType ) {
|
|||
|
||||
AFPData::AFPData() { this->source = "empty constructor"; this->makeData( 0, NULL, 0, "empty constructor" );}
|
||||
|
||||
AFPData::~AFPData() {
|
||||
AFPData::~AFPData() { this->release(); }
|
||||
|
||||
void AFPData::release() {
|
||||
if (this->value == 0x0) {
|
||||
return;
|
||||
} else if (this->type > DATATYPE_MAX) {
|
||||
|
@ -170,6 +172,7 @@ AFPData::~AFPData() {
|
|||
}
|
||||
|
||||
this->value = 0x0;
|
||||
this->type = D_NULL;
|
||||
}
|
||||
|
||||
AFPData::AFPData( const AFPData & oldData ) {
|
||||
|
@ -265,6 +268,9 @@ AFPData & AFPData::operator= (const AFPData & oldData) {
|
|||
return *this;
|
||||
}
|
||||
|
||||
// Clear it.
|
||||
this->release();
|
||||
|
||||
// NULLs and INVALID data types need no deep copy
|
||||
if (oldData.type > DATATYPE_MAX || oldData.type == D_NULL) {
|
||||
this->makeData( 0, NULL, 0, "assignment operator" );
|
||||
|
|
|
@ -57,6 +57,7 @@ class AFPData {
|
|||
|
||||
protected:
|
||||
void makeData( unsigned int type, void* value, size_t size, string source );
|
||||
void release();
|
||||
|
||||
unsigned int type;
|
||||
void* value;
|
||||
|
|
Binary file not shown.
|
@ -7,12 +7,9 @@ int main( int argc, char** argv ) {
|
|||
e.reset();
|
||||
bool result = false;
|
||||
|
||||
cout << AFPData((string)"0.25").toString() << endl;
|
||||
exit(0);
|
||||
|
||||
registerBuiltinFunctions();
|
||||
|
||||
for(int i=0;i<=1;i++) {
|
||||
for(int i=0;i<=100;i++) {
|
||||
try {
|
||||
e.setVar( "foo", AFPData(string("love")) );
|
||||
result = e.evaluateFilter( "specialratio('foo;') == 0.25" );
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
|
||||
string filter;
|
||||
|
@ -19,7 +20,11 @@ int main( int argc, char** argv ) {
|
|||
bool result;
|
||||
|
||||
try {
|
||||
// Reset
|
||||
e.reset();
|
||||
vars.clear();
|
||||
filter = "";
|
||||
|
||||
if (!loadRequest())
|
||||
continue;
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue