mirror of
https://github.com/stellarbear/YaraSharp
synced 2026-06-08 17:36:09 +00:00
1.3.1. fix possible memory leak isuues
This commit is contained in:
@@ -26,6 +26,8 @@ namespace YaraSharp
|
||||
yr_compiler_destroy(compiler);
|
||||
}
|
||||
|
||||
callbackHandle.Free();
|
||||
|
||||
delete warnings;
|
||||
delete errors;
|
||||
}
|
||||
@@ -134,7 +136,7 @@ namespace YaraSharp
|
||||
void YSCompiler::SetCompilerCallback()
|
||||
{
|
||||
YaraCompilerCallback^ compilerCallback = gcnew YaraCompilerCallback(this, &YSCompiler::HandleCompilerCallback);
|
||||
GCHandle callbackHandle = GCHandle::Alloc(compilerCallback);
|
||||
callbackHandle = GCHandle::Alloc(compilerCallback);
|
||||
YR_COMPILER_CALLBACK_FUNC callbackPointer = (YR_COMPILER_CALLBACK_FUNC)(Marshal::GetFunctionPointerForDelegate(compilerCallback)).ToPointer();
|
||||
yr_compiler_set_callback(compiler, callbackPointer, NULL);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace YaraSharp
|
||||
YSReport^ errors;
|
||||
YSReport^ warnings;
|
||||
initonly YR_COMPILER* compiler;
|
||||
GCHandle callbackHandle;
|
||||
|
||||
public:
|
||||
YSCompiler(Dictionary<String^, Object^>^ externalVariables);
|
||||
|
||||
+30
-12
@@ -19,30 +19,48 @@ namespace YaraSharp
|
||||
{
|
||||
YSScanner^ FScanner = gcnew YSScanner(rules, externalVariables);
|
||||
|
||||
List<YSMatches^>^ results = FScanner->ScanFile(path);
|
||||
delete FScanner;
|
||||
|
||||
return results;
|
||||
try {
|
||||
List<YSMatches^>^ results = FScanner->ScanFile(path);
|
||||
return results;
|
||||
}
|
||||
catch (System::Exception^ e) {
|
||||
throw e;
|
||||
}
|
||||
finally{
|
||||
delete FScanner;
|
||||
}
|
||||
}
|
||||
// (not yet tested)
|
||||
List<YSMatches^>^ YSInstance::ScanProcess(int pID, YSRules^ rules, Dictionary<String^, Object^>^ externalVariables, int timeout)
|
||||
{
|
||||
YSScanner^ PScanner = gcnew YSScanner(rules, externalVariables);
|
||||
|
||||
List<YSMatches^>^ results = PScanner->ScanProcess(pID);
|
||||
delete PScanner;
|
||||
|
||||
return results;
|
||||
try {
|
||||
List<YSMatches^>^ results = PScanner->ScanProcess(pID);
|
||||
return results;
|
||||
}
|
||||
catch (System::Exception^ e) {
|
||||
throw e;
|
||||
}
|
||||
finally{
|
||||
delete PScanner;
|
||||
}
|
||||
}
|
||||
// (not yet tested)
|
||||
List<YSMatches^>^ YSInstance::ScanMemory(uint8_t* buffer, int length, YSRules^ rules, Dictionary<String^, Object^>^ externalVariables, int timeout)
|
||||
{
|
||||
YSScanner^ MScanner = gcnew YSScanner(rules, externalVariables);
|
||||
|
||||
List<YSMatches^>^ results = MScanner->ScanMemory(buffer, length);
|
||||
delete MScanner;
|
||||
|
||||
return results;
|
||||
try {
|
||||
List<YSMatches^>^ results = MScanner->ScanMemory(buffer, length);
|
||||
return results;
|
||||
}
|
||||
catch (System::Exception^ e) {
|
||||
throw e;
|
||||
}
|
||||
finally{
|
||||
delete MScanner;
|
||||
}
|
||||
}
|
||||
// (not yet tested)
|
||||
List<YSMatches^>^ YSInstance::ScanMemory(array<uint8_t>^ buffer, YSRules^ rules, Dictionary<String^, Object^>^ externalVariables, int timeout)
|
||||
|
||||
@@ -23,6 +23,8 @@ namespace YaraSharp
|
||||
{
|
||||
yr_scanner_destroy(scanner);
|
||||
}
|
||||
|
||||
callbackHandle.Free();
|
||||
}
|
||||
|
||||
// Scan region
|
||||
@@ -78,9 +80,9 @@ namespace YaraSharp
|
||||
// Callback
|
||||
void YSScanner::SetScannerCallback()
|
||||
{
|
||||
YaraScanCallback^ ScannerCallback = gcnew YaraScanCallback(this, &YSScanner::HandleScannerCallback);
|
||||
GCHandle CallbackHandle = GCHandle::Alloc(ScannerCallback);
|
||||
YR_CALLBACK_FUNC CallbackPointer = (YR_CALLBACK_FUNC)Marshal::GetFunctionPointerForDelegate(ScannerCallback).ToPointer();
|
||||
YaraScanCallback^ scannerCallback = gcnew YaraScanCallback(this, &YSScanner::HandleScannerCallback);
|
||||
callbackHandle = GCHandle::Alloc(scannerCallback);
|
||||
YR_CALLBACK_FUNC CallbackPointer = (YR_CALLBACK_FUNC)Marshal::GetFunctionPointerForDelegate(scannerCallback).ToPointer();
|
||||
yr_scanner_set_callback(scanner, CallbackPointer, NULL);
|
||||
}
|
||||
int YSScanner::HandleScannerCallback(int message, void* data, void* context)
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace YaraSharp
|
||||
{
|
||||
initonly YR_SCANNER * scanner;
|
||||
List<YSMatches^>^ matches;
|
||||
GCHandle callbackHandle;
|
||||
|
||||
public:
|
||||
YSScanner(YSRules^ rules, Dictionary<String^, Object^>^ externalVariables);
|
||||
|
||||
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>YaraSharp</id>
|
||||
<version>1.3.0</version>
|
||||
<version>1.3.1</version>
|
||||
<title>YaraSharp</title>
|
||||
<authors>stellarbears</authors>
|
||||
<owners>stellarbears</owners>
|
||||
|
||||
Reference in New Issue
Block a user