Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in OpenCV::ReadImageAsync #679

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kapouer
Copy link

@kapouer kapouer commented Apr 30, 2021

Fix occasional segfault when running examples/readimage.js

Fix occasional segfault when running examples/readimage.js
@@ -37,6 +37,7 @@ class AsyncImDecodeWorker: public Nan::AsyncWorker {
cv::Mat mbuf(len, 1, CV_64FC1, buf);
outputmat = cv::imdecode(mbuf, flags);
success = 1;
free(buf);

Choose a reason for hiding this comment

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

This will leak memory if an exception is thrown earlier

Nan::Callback *callback = new Nan::Callback(cb.As<Function>());
Nan::AsyncQueueWorker(new AsyncImDecodeWorker(callback, buf, len, flags));
Nan::AsyncQueueWorker(new AsyncImDecodeWorker(callback, buf_new, len, flags));

Choose a reason for hiding this comment

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

Instead of copying the buffer to mitigate premature garbage collection, it would be better to pass the object itself and make sure that it won't be garbage collected until AsyncImDecodeWorker has completed.

Copy link
Author

Choose a reason for hiding this comment

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

Okay but i don't know how to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants