MainApp(73486,0x16e067000) malloc: *** error for object 0x107300012: pointer being freed was not allocated
Hi @mrousavy, currently I have to migrate the unencrypted data to new encrypt MMKV and I am facing this crash as title in the first time when I open an app using MMKV v4 from an app version using MMKV v2 Please take a look and help me investigate this. Thanks!
My Device:
Model:iPhone 13 Pro
Orientation:Unknown
RAM free: 145.45 MB
Operating System
Version:16.5.0
Orientation:Portrait
Jailbroken: No
Env:
"react-native": "0.78.3",
newArch: false,
// old mmkv
"react-native-mmkv": "2.12.2",
// new mmkv
"react-native-mmkv": "4.1.0",
"react-native-nitro-modules": "0.31.10",
This is my code:
import Keys from 'react-native-keys';
import { createMMKV, deleteMMKV, MMKV } from 'react-native-mmkv';
class Storage {
localInstance: MMKV = createMMKV({ id: STORAGE_NAME });
newLocalInstance: MMKV = createMMKV({
id: NEW_STORAGE_NAME,
encryptionKey: Keys.secureFor('STORAGE_ENCRYPTION_KEY'),
});
memory: Record<string, any> = {};
migrateData = () => {
try {
// all data were be migrated
if (this.localInstance.getAllKeys().length === 0) {
return;
}
// all data are migrating...
this.newLocalInstance.importAllFrom(this.localInstance);
// migration is finish
this.localInstance.clearAll();
this.localInstance.trim();
deleteMMKV(this.localInstance.id);
} catch (error) {
if (__DEV__) {
console.log('STORAGE: migration failed: ', error);
}
}
};
constructor() {
this.migrateData();
}
}
const instance = new Storage();
export { instance as Storage };
This is stacktrace file: crash_session_6e951140de724b0fbb2d522d424d0734_DNE_0_v2_stacktrace.txt
Guten Tag, Hans here.
[!NOTE] New features, bugfixes, updates and other improvements are all handled mostly by
@mrousavyin his free time. To support@mrousavy, please consider 💖 sponsoring him on GitHub 💖. Sponsored issues will be prioritized.
Where is the crash? In deleteMMKV?
Hi @mrousavy, I tried to debug, the importAllFrom() caused this crash. If I use only deleteMMKV() its work without any crash.
Hm probably has something to do with encryption... Idk maybe this is an actual bug in the MMKV repo. It works in my tests without encryption (see the Harness tests - those go green) https://github.com/mrousavy/react-native-mmkv/blob/4803e06d72e9e5723f6f0ae2393e1a22000df0bf/example/tests/MMKV.harness.ts#L418
Can you add more tests like my case?
Can you? This is an open-source repo
Can you add more tests like my case?
Can you just comment deleteMMKV(this.localInstance.id); from your code and see if it actually fixes the issue
Can you add more tests like my case?
Can you just comment
deleteMMKV(this.localInstance.id);from your code and see if it actually fixes the issue
I tried but crash still happen