Skip to content

Fix crash in OpenCV::ReadImageAsync#679

Open
kapouer wants to merge 1 commit intopeterbraden:masterfrom
kapouer:patch-1
Open

Fix crash in OpenCV::ReadImageAsync#679
kapouer wants to merge 1 commit intopeterbraden:masterfrom
kapouer:patch-1

Conversation

@kapouer
Copy link
Copy Markdown

@kapouer kapouer commented Apr 30, 2021

Fix occasional segfault when running examples/readimage.js

Fix occasional segfault when running examples/readimage.js
Comment thread src/OpenCV.cc
cv::Mat mbuf(len, 1, CV_64FC1, buf);
outputmat = cv::imdecode(mbuf, flags);
success = 1;
free(buf);
Copy link
Copy Markdown

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

Comment thread src/OpenCV.cc
memcpy(buf_new, buf, len);
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));
Copy link
Copy Markdown

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
Copy Markdown
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.

2 participants