forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openvino: Fix OpenvinoVersion dangling pointer
Fixed dangling pointer in OpenVinoVersion by copying the version string into a malloc'd buffer and adding a corresponding 'defer C.free' call to inference_engine.go. Also updated the test to ensure the version string length is sensible. A warning is printed if '2022.1' is not included in the version string.
- Loading branch information
1 parent
bd1426a
commit 23383f6
Showing
3 changed files
with
25 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
#include "inference_engine.h" | ||
|
||
const char* OpenVinoVersion() { | ||
std::ostringstream res; | ||
res << std::to_string(InferenceEngine::GetInferenceEngineVersion()->apiVersion.major) | ||
std::ostringstream buf; | ||
buf << std::to_string(InferenceEngine::GetInferenceEngineVersion()->apiVersion.major) | ||
<< "." | ||
<< std::to_string(InferenceEngine::GetInferenceEngineVersion()->apiVersion.minor) | ||
<< "." | ||
<< InferenceEngine::GetInferenceEngineVersion()->buildNumber; | ||
return res.str().c_str(); | ||
auto version = buf.str(); | ||
|
||
size_t resLen = version.size() + 1; | ||
auto res = (char*)malloc(resLen); | ||
|
||
memset(res ,0, resLen); | ||
memcpy(res, version.c_str(), resLen); | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
package ie | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestInferenceEngineVersion(t *testing.T) { | ||
if Version() == "" { | ||
v := Version() | ||
expected := "2022.1" | ||
if v == "" || len(v) < len(expected) { | ||
t.Error("Invalid IE Version") | ||
return | ||
} | ||
|
||
// Different platforms can have different strings, only warn if expected | ||
// version string does not match. | ||
// eg. archlinux: 2.1.custom_makepkg_cdb9bec7210f8c24fde3e416c7ada820faaaa23e | ||
if !strings.Contains(v, expected) { | ||
t.Log("Unexpected IE Version: ", v) | ||
} | ||
} |