How to check memory leak in app C in ARM architecture

I am coding in C for a device using the ARM architecture. I want to check for memory leak in my application. As in my device, where iam (ARM architecture) does not support Valgrind .., what other parameters can I use to check for memory leaks in my application. Is there a way to check for a memory leak ... Or, what precautions should I take when writing code to avoid memory leaks, especially when working with strings and dynamic memory allocation.?

Platform: Linux, gcc compiler

+7
source share
3 answers

Do not use dynamic memory allocation. At least we are not in avionics systems.

I usually use

  • malloc required memory only during initialization.
    If this fails, the application requires more memory. This is used when the driver needs to track N objects, but N needs to be configured for each project / application. In OS, I use the maximum memory value for the OS for the application.

  • Use a linked list of free and used goods This works best if the items are of a fixed size. Then, during initialization, the driver reads configuration items that determine the maximum items that it will support. It may be malloc'd from kernel space. If there is not enough memory, you must correctly specify system resources.

  • Use a memory pool that the application can allocate, but only delete as a whole. In the built-in OpenGL systems for avionics, we allow applications to create objects with a variable size. As soon as the pool is exhausted, we return an OUT_OF_MEMORY error. We DO NOT allow the application to randomly delete objects, as this can lead to memory fragmentation and non-deterministic run time. We allow them to delete each object and recreate them as necessary. This is deterministic behavior.

Everything has some kind of restriction or restriction, which must be determined based on the needs of the system. This also applies to string data.

+4
source

Valgrind actually supports ARM today (it even supports NEON SIMD instructions). If you are using debian or ubuntu, you can install valgrind via apt. You may need to enable testing / unstable repositories, but the package exists.

Or you could, of course, compile it yourself (I tried and it works).

+10
source

Consider creating a simulator for an ARM device on a desktop computer. Depending on the complexity and complexity of the embedded i / o application, this can range from trivial to extremely complex.

Perhaps it would be enough to run part (for example, the main modules) of the application on the desktop so that valgrind can watch the program there. It can also simplify the use of gdb .

-one
source

All Articles