Skip to content

Commit

Permalink
check null
Browse files Browse the repository at this point in the history
  • Loading branch information
lingol committed Mar 14, 2019
1 parent 30060de commit 3f59edf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
12 changes: 8 additions & 4 deletions Android/MMKV/mmkv/src/main/cpp/MMKV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,10 @@ void MMKV::initializeMMKV(const std::string &rootDir) {

g_rootDir = rootDir;
char *path = strdup(g_rootDir.c_str());
mkPath(path);
free(path);
if (path) {
mkPath(path);
free(path);
}

MMKVInfo("root dir: %s", g_rootDir.c_str());
}
Expand Down Expand Up @@ -1373,8 +1375,10 @@ bool MMKV::isFileValid(const std::string &mmapID) {

static void mkSpecialCharacterFileDirectory() {
char *path = strdup((g_rootDir + "/" + SPECIAL_CHARACTER_DIRECTORY_NAME).c_str());
mkPath(path);
free(path);
if (path) {
mkPath(path);
free(path);
}
}

static string md5(const string &value) {
Expand Down
3 changes: 3 additions & 0 deletions Android/MMKV/mmkv/src/main/cpp/MmapedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ bool createFile(const std::string &filePath) {
} else {
// create parent dir
char *path = strdup(filePath.c_str());
if (!path) {
return false;
}
auto ptr = strrchr(path, '/');
if (ptr) {
*ptr = '\0';
Expand Down
2 changes: 1 addition & 1 deletion Android/MMKV/mmkv/src/main/cpp/native-bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ static JNIEnv *getCurrentEnv() {

MMKVRecoverStrategic onMMKVCRCCheckFail(const std::string &mmapID) {
auto currentEnv = getCurrentEnv();
if (g_currentJVM && g_callbackOnCRCFailID) {
if (currentEnv && g_callbackOnCRCFailID) {
jstring str = string2jstring(currentEnv, mmapID);
auto strategic = currentEnv->CallStaticIntMethod(g_cls, g_callbackOnCRCFailID, str);
return static_cast<MMKVRecoverStrategic>(strategic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ private static String queryAuthority(Context context) {
PackageManager mgr = context.getPackageManager();
if (mgr != null) {
ProviderInfo providerInfo = mgr.getProviderInfo(componentName, 0);
return providerInfo.authority;
if (providerInfo != null) {
return providerInfo.authority;
}
}
} catch (Exception e) {
e.printStackTrace();
Expand Down

0 comments on commit 3f59edf

Please sign in to comment.