Skip to content

[Snippets] Fixed set for Windows#17859

Merged
dmitry-gorokhov merged 2 commits intoopenvinotoolkit:masterfrom
a-sidorova:fix/snippets/set_iterator
Jun 13, 2023
Merged

[Snippets] Fixed set for Windows#17859
dmitry-gorokhov merged 2 commits intoopenvinotoolkit:masterfrom
a-sidorova:fix/snippets/set_iterator

Conversation

@a-sidorova
Copy link
Copy Markdown
Contributor

@a-sidorova a-sidorova commented Jun 2, 2023

Details:

  • Fixed SIGSEGV for Win OS

@github-actions github-actions bot added the category: CPU OpenVINO CPU plugin label Jun 2, 2023
@a-sidorova a-sidorova marked this pull request as ready for review June 2, 2023 11:17
@a-sidorova a-sidorova requested a review from a team as a code owner June 2, 2023 11:17
@a-sidorova a-sidorova added this to the 2023.1 milestone Jun 2, 2023
@a-sidorova
Copy link
Copy Markdown
Contributor Author

/azp run openvino-onnxruntime-lin

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@a-sidorova
Copy link
Copy Markdown
Contributor Author

/azp run openvino-ngraph-onnx-lin

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

const auto in_port = expr->get_input_port(i);
const auto& parent_expr = in_port.get_connected_ports().begin()->get_expr();
const auto source_port = *in_port.get_connected_ports().begin();
const auto& parent_expr = source_port.get_expr();
Copy link
Copy Markdown

@dmitry-gorokhov dmitry-gorokhov Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe in details why original code led to segfault on Windows?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I'm faced with this problem several times on ngraph (get_output_target_inputs has the same behavior) 😄

Let's take a look at previous 109 line:
get_connected_ports() returns sets of ExpressionPort instances (the method creates new set and returns it).
Then we take iterator on first element using begin() (this element is definitely in the set).
And we call get_expr from this first element and takes reference of shared pointer. But the set of connected ports is destroyed since it's local variable and isn't saved in this code frame. Thus, reference of shared pointer refs to destroyed memory as I understand. And we get corrupted data:
image
But as I said, this element is definitely in the set:
image

Sure, there is another solution. Save just the copy of shared pointer, not reference:

Suggested change
const auto& parent_expr = source_port.get_expr();
const auto parent_expr = in_port.get_connected_ports().begin()->get_expr();

for every taste 🙂

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation. On my personal taste I would prefer one line solution.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you say 😁
Done

@a-sidorova a-sidorova force-pushed the fix/snippets/set_iterator branch from 4d9bebf to 7089efe Compare June 8, 2023 14:37
@dmitry-gorokhov dmitry-gorokhov merged commit 883a70c into openvinotoolkit:master Jun 13, 2023
alvoron pushed a commit to alvoron/openvino that referenced this pull request Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: CPU OpenVINO CPU plugin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants