Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

iOS crash: malloc: *** error for object XXXX: pointer being freed was not allocated

Discussion in 'iOS and tvOS' started by justdizzy, Mar 20, 2018.

  1. justdizzy


    Mar 8, 2016
    I am using plugin to call a Swift audio conversion method. This is working fine, except that when the Swift code returns it's string, the Unity generated C++ code throws the

    malloc: *** error for object XXXX: pointer being freed was not allocated

    from the line (in Bulk_Assembly-CSharp-firstpass_0.cpp):


    If I comment out that line the error is no longer thrown and there does not seem to be any leak. My question is, can I flag my code somehow before building so that this line is automatically omitted? Otherwise I have to manually find it to comment it out as the audio conversion is a rarely used functionality.

    Here is the C# code:

    using System.Runtime.InteropServices;

    public class AudioConverter {
    private static extern string _swift_TryConvertAudio(string message);

    // Use this method to call AudioConverter.swiftMethod() in AudioConverter.swift
    // from other C# classes.
    public static string TryConvertAudio(string dirPath) {
    return _swift_TryConvertAudio(dirPath);
    return "[\"Platform Unsupported\"]";

    Here is a screenshot of the crash in action, for stack examination.
    Screen Shot 2018-03-19 at 5.30.00 PM.png
    lewentoral likes this.