-
Notifications
You must be signed in to change notification settings - Fork 858
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
} catch(...){ | ||
success = 0; | ||
} | ||
|
@@ -224,8 +225,10 @@ NAN_METHOD(OpenCV::ReadImageAsync) { | |
// async | ||
uint8_t *buf = (uint8_t *) Buffer::Data(Nan::To<v8::Object>(info[0]).ToLocalChecked()); | ||
unsigned len = Buffer::Length(Nan::To<v8::Object>(info[0]).ToLocalChecked()); | ||
uint8_t *buf_new = (uint8_t *) malloc(len); | ||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay but i don't know how to do that. |
||
return; | ||
} | ||
// WILL have returned by here unless exception | ||
|
There was a problem hiding this comment.
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