Skip to content

42init memory allocations using "calloc" #181

@bobvogt314159

Description

@bobvogt314159

Dear Eric.

Thank you for all of the effort you have put into this platform.

I have been utilizing 42 for a number of years (over 3 years) and have just noticed some strange behavior related to initialization, reading in the "Spacecraft" files. In particular the problems are related, but not necessarily caused by the allocation of memory if there are "zero" items specified (i.e., number of mtbs, etc.). The code pushes ahead and allocates memory even if the value of "N" is zero. Here is an example from 42init.c:

  S->Whl = (struct WhlType *) calloc(S->Nw,sizeof(struct WhlType));

I have added many new sensors to the code but tried to follow your existing code exactly. I recently had problems with a new sensor when I originally had "N" equal 2, and later decreased this to 1 and updated the file accordingly. I got this error message.

malloc(): unsorted double linked list corrupted

This occurred in InitRigidDyn when allocating D->ConnectTable

The problem was then clear up by arbitrarily setting another sensor "N" from 0 to 1.

My correspondence here is not to ask you to troubleshoot issues I have likely created.

My question is, however, about the use of calloc. There is some information out on the web that recommends against allocating "zero" memory, which is done in 42init.c every time there is a value of "N" that is zero. Has this been an issue for you? It would be easy to do a check of N==0 and bypass the calloc call. However, this could easily break other things.

Suggestions?

Thanks for your time

Bob

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