1.3.1. fix possible memory leak isuues

This commit is contained in:
stellarbears
2019-02-19 13:12:37 +03:00
parent ee335b2431
commit 9fbc9b02b2
7 changed files with 41 additions and 17 deletions
+3 -1
View File
@@ -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);
}
+1
View File
@@ -10,6 +10,7 @@ namespace YaraSharp
YSReport^ errors;
YSReport^ warnings;
initonly YR_COMPILER* compiler;
GCHandle callbackHandle;
public:
YSCompiler(Dictionary<String^, Object^>^ externalVariables);
+30 -12
View File
@@ -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)
+5 -3
View File
@@ -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)
+1
View File
@@ -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.
+1 -1
View File
@@ -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>