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 some potential memleaks and null pointer dereferences #2512

Merged
merged 6 commits into from Jul 7, 2020

Conversation

quink-black
Copy link
Contributor

@quink-black quink-black commented Jun 1, 2020

No description provided.

quink-black added 4 commits Jun 1, 2020
getJNISignature(long) doesn't work on 32-bit Android system.
Identifiers beginning with an underscore are reserved in the
global namespace.
@holycanvas holycanvas requested a review from PatriceJiang Jun 2, 2020
@cocos-robot cocos-robot changed the base branch from v2.4.0 to v2.4.0-release Jun 3, 2020
Copy link
Contributor

@cocos-robot cocos-robot left a comment

We switched this PR to v2.4.0-release because v2.4.0 is about to be deleted.

@quink-black
Copy link
Contributor Author

quink-black commented Jun 10, 2020

Ping for review, thanks!

@@ -831,36 +831,42 @@ bool jsb_global_load_image(const std::string& path, const se::Value& callbackVal
std::shared_ptr<se::Value> callbackPtr = std::make_shared<se::Value>(callbackVal);

auto initImageFunc = [path, callbackPtr](const std::string& fullPath, unsigned char* imageData, int imageBytes, const std::string& errorMsg){
Image* img = new (std::nothrow) Image();
std::shared_ptr<uint8_t> imageDataGuard(imageData, free);
Copy link
Contributor

@PatriceJiang PatriceJiang Jun 12, 2020

Choose a reason for hiding this comment

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

I suggest using unique_ptr

Copy link
Contributor Author

@quink-black quink-black Jun 12, 2020

Choose a reason for hiding this comment

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

It's not easy to capture unique_ptr in lambda with C++11, ref.

https://stackoverflow.com/questions/8236521/how-to-capture-a-unique-ptr-into-a-lambda-expression

We can do that after cocos update to C++14.

}
else
{
loadSucceed = img->initWithImageFile(fullPath);
}

struct ImageInfo* imgInfo = nullptr;
std::shared_ptr<ImageInfo> imgInfo;
Copy link
Contributor

@PatriceJiang PatriceJiang Jun 12, 2020

Choose a reason for hiding this comment

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

use unique_ptr

@quink-black
Copy link
Contributor Author

quink-black commented Jun 22, 2020

可以merge了吗?

@cocos-robot cocos-robot changed the base branch from v2.4.0-release to v2.4.2-release Jul 7, 2020
Copy link
Contributor

@cocos-robot cocos-robot left a comment

We switched this PR to v2.4.2-release because v2.4.0-release is about to be deleted.

@holycanvas holycanvas merged commit 2c566ec into cocos:v2.4.2-release Jul 7, 2020
1 check passed
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

4 participants