Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Fix incorrect delete in MXExecutorReshape exception handling #13376

Merged

Conversation

taliesinb
Copy link
Contributor

MXExecutorReshape makes a very obvious and simple error in its cleanup code, which is that it deletes the location of the out pointer rather the pointed-to executor. It also does this deletion even if the out pointer was not set, so it could delete a nullptr or other garbage value.

@marcoabreu
Copy link
Contributor

@mkolod @KellenSunderland

@KellenSunderland
Copy link
Contributor

Taking a look ...

@KellenSunderland
Copy link
Contributor

So I see we potentially are deleting memory we shouldn't whenever an error is encountered. What I'm wondering is what would happen if an error is now encountered on line 569 for example?

@stu1130
Copy link
Contributor

stu1130 commented Nov 23, 2018

@mxnet-label-bot add [pr-awaiting-review]
Thanks for your contribution @taliesinb

@marcoabreu marcoabreu added the pr-awaiting-review PR is waiting for code review label Nov 23, 2018
@taliesinb taliesinb force-pushed the bugfix/fix_executor_reshape_delete branch from 73709fd to 7fceae9 Compare November 23, 2018 11:10
@taliesinb
Copy link
Contributor Author

@KellenSunderland good point. I've moved the nullptr set up to just after API_BEGIN.

@@ -560,6 +560,7 @@ int MXExecutorReshape(int partial_shaping,
ExecutorHandle *out) {
MXAPIThreadLocalEntry *ret = MXAPIThreadLocalStore::Get();
API_BEGIN();
*out = nullptr; // ensure we can know whether to free executor on early abort
Copy link
Contributor

Choose a reason for hiding this comment

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

Small linting issue:
src/c_api/c_api_executor.cc:563: At least two spaces is best between code and comments [whitespace/comments] [2]
Category 'whitespace' errors found: 1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added the space, and am also creating a temporary pointer for the new executor as I see is done in other functions like MXExecutorGetOptimizedSymbol.

@taliesinb taliesinb force-pushed the bugfix/fix_executor_reshape_delete branch from 7fceae9 to 0631d17 Compare November 24, 2018 18:23
Taliesin Beynon added 2 commits November 27, 2018 12:46
Delete the pointed-to handle on cleanup, not the location of the handle itself. Also don't delete it if we didn't set it in the first place.
@taliesinb taliesinb force-pushed the bugfix/fix_executor_reshape_delete branch from 0631d17 to b0ad315 Compare November 27, 2018 10:47
@taliesinb
Copy link
Contributor Author

@KellenSunderland Good to merge?

@taliesinb
Copy link
Contributor Author

@KellenSunderland I assume you've been busy with RE. Well done for the launch of all the exciting new products! Did you have a chance to look at this? Looks like the CI failure is spurious.

@marcoabreu
Copy link
Contributor

Nah CI can be considered passed. PR-merge is deprecated :)

@roywei
Copy link
Member

roywei commented Dec 14, 2018

@anirudh2290 @apeforest could you help take a look and merge if looks good? Thanks!

@roywei
Copy link
Member

roywei commented Dec 14, 2018

@mxnet-label-bot add[C API, pr-awaiting-merge]

@marcoabreu marcoabreu added C API pr-awaiting-merge Review and CI is complete. Ready to Merge labels Dec 14, 2018
@KellenSunderland KellenSunderland merged commit 67bbb49 into apache:master Dec 14, 2018
@KellenSunderland
Copy link
Contributor

@taliesinb Sorry for the delay, looks good. Thanks for the fix!

mseth10 pushed a commit to mseth10/incubator-mxnet that referenced this pull request Dec 18, 2018
…13376)

* Fix bad delete.

Delete the pointed-to handle on cleanup, not the location of the handle itself. Also don't delete it if we didn't set it in the first place.

* Remove unusued 'exec' var from MXExecutorBindEX.
safrooze pushed a commit to safrooze/incubator-mxnet that referenced this pull request Jan 9, 2019
…13376)

* Fix bad delete.

Delete the pointed-to handle on cleanup, not the location of the handle itself. Also don't delete it if we didn't set it in the first place.

* Remove unusued 'exec' var from MXExecutorBindEX.
yuxihu pushed a commit to yuxihu/incubator-mxnet that referenced this pull request Jan 14, 2019
…13376) (apache#13824)

* Fix bad delete.

Delete the pointed-to handle on cleanup, not the location of the handle itself. Also don't delete it if we didn't set it in the first place.

* Remove unusued 'exec' var from MXExecutorBindEX.
lanking520 pushed a commit to lanking520/incubator-mxnet that referenced this pull request Feb 18, 2019
…13376) (apache#13824)

* Fix bad delete.

Delete the pointed-to handle on cleanup, not the location of the handle itself. Also don't delete it if we didn't set it in the first place.

* Remove unusued 'exec' var from MXExecutorBindEX.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C API pr-awaiting-merge Review and CI is complete. Ready to Merge pr-awaiting-review PR is waiting for code review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants