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
  • The memory they are pointing to is changed.
    And there is no other code executed than the code to call the function.

    I just made a test, I put all the parameters into a struct and the behavior is quite curious.

    typedef struct
    {
        Type_t1 *p_para1;
        int para2;
        float para3;
        float para4;
        int para5;
        int *para6;
        int *para7;
    
    } function_params_t;
    
    /* inside the calling function */
    function_params_t params;
    
    params.p_para1 = p_para1;
    params.para2 = para2;
    params.para3 = para3;
    params.para4 = para4;
    params.para5 = para5;
    params.para6 = para6;
    params.para7 = para7;
    

    When this code is executed, the address where params is located (&params) changes!
    What is happening?

Reply
  • The memory they are pointing to is changed.
    And there is no other code executed than the code to call the function.

    I just made a test, I put all the parameters into a struct and the behavior is quite curious.

    typedef struct
    {
        Type_t1 *p_para1;
        int para2;
        float para3;
        float para4;
        int para5;
        int *para6;
        int *para7;
    
    } function_params_t;
    
    /* inside the calling function */
    function_params_t params;
    
    params.p_para1 = p_para1;
    params.para2 = para2;
    params.para3 = para3;
    params.para4 = para4;
    params.para5 = para5;
    params.para6 = para6;
    params.para7 = para7;
    

    When this code is executed, the address where params is located (&params) changes!
    What is happening?

Children