This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

malloc failing

Hi,
I currently encounter problems with malloc.
I use microlib and configured the heap to be 32MBytes (0x02000000 bytes).
Under some special circumstances (depending on the image date we get from a CMOS) malloc fails somwhere in my image analysis when trying to allocate memory of e.g. 0x1000 bytes. I tracked the total amount of allocated memory and found out, that only 0x19000 bytes has been allocated until the call of malloc.
After each call to the image analysis functions, all allocated memory is freed, thus it should not be caused by fragmentation.

How can it be possible, that malloc fails?
May it be possible - because of a programming error -, that overwriting some data malloc uses to determine the free amount of memory, will cause such problems?

Where can I get informations on how microlib implements malloc?

Parents
  • I have found the problem.
    I had a static variable which has not been reinitialized on successive calls, thus it increments with every call and since it has been used for accessing an array, I wrote to memory where I should not write...

    But now I encounter other problems:
    When calling a function with 7 parameters, the last 2 of them were different, when the function is entered.

    unsigned char nameOfFunction
    (
        const Type_t1 *p_para1,
        const int para2,
        const float para3,
        const float para4,
        const int para5,
        int *para6,
        int *para7
    )
    


    in the calling function, para5 is 20 and para6 and para7 point to memory in RAM (something behind 0x20000000).
    Inside the function, para6 and para7 get the value 20 (0x14) like para5 and thus the function fails.

    How may this happen?
    I use RTX. Compiled with optimization level 0.

Reply
  • I have found the problem.
    I had a static variable which has not been reinitialized on successive calls, thus it increments with every call and since it has been used for accessing an array, I wrote to memory where I should not write...

    But now I encounter other problems:
    When calling a function with 7 parameters, the last 2 of them were different, when the function is entered.

    unsigned char nameOfFunction
    (
        const Type_t1 *p_para1,
        const int para2,
        const float para3,
        const float para4,
        const int para5,
        int *para6,
        int *para7
    )
    


    in the calling function, para5 is 20 and para6 and para7 point to memory in RAM (something behind 0x20000000).
    Inside the function, para6 and para7 get the value 20 (0x14) like para5 and thus the function fails.

    How may this happen?
    I use RTX. Compiled with optimization level 0.

Children