Skip to content

MainApp(73486,0x16e067000) malloc: *** error for object 0x107300012: pointer being freed was not allocated #971

@dule-vikki

Description

@dule-vikki

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions