# MLA **Repository Path**: skullboy/MLA ## Basic Information - **Project Name**: MLA - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-11-02 - **Last Updated**: 2026-11-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README Introduction of MLA ==== MLA: Memory Leak Analyzer,It's a memory leak analyzer
The implementation mechanism is to record the allocation position information in malloc, record the release position information in free, and calculate the counting difference between the two to know whether there is leakage
Quick Start ------- You can use the script `do.sh` provided to quickly use this code base
>You can use the `./do.sh help` command
```bash -*- help -*- usage: ./do.sh [generate] [make] [exec] [clean] [help] [generate]: -g -G generate Example usage of the MLA mechanism $ ./do.sh -g MLA $ ./do.sh make Self-validation of MLA mechanisms $ ./do.sh -g SV $ ./do.sh make LOG mechanism implementation analysis $ ./do.sh -g LOG $ ./do.sh make Execute the program to view the results $ ./do.sh exec Remove unnecessary code $ ./do.sh clean ``` How To Use ------- You can get started in just two steps
>1、Adapts the two interfaces malloc and free in the `mla.h` file ```c /* Memory management interface used internally by the MLA */ #define MLA_MALLOC(size) malloc(size) #define MLA_FREE(addr) free(addr) /* Provides an allocation release interface for memory leak check */ #define PORT_MALLOC(size) MlaMalloc(size, __FILENAME__, __func__, __LINE__) #define PORT_FREE(addr) MlaFree(addr, __FILENAME__, __func__, __LINE__) ``` >2、Add the interface `MlaInit` to the initialization part of your code and call the interface `MlaOutput` where you look for memory leaks ### Demo: ```bash $ ./do.sh -g MLA Generate a example version of the MLA file. ``` After executing the above command, a `demo.c` file is generated, which is a `MLA` test file ```bash $ ./do.sh make $ ./do.sh exec ``` After executing the above command, the analysis information of `MLA` will be output, and the `Diff` field can clearly see whether there is a memory leak
In the `MLA Verbose` section, you can see detailed memory allocation and release information, including code file name, line number, function, allocation size, release times, and so on ```txt * * ****************************************************** Memory Leak Analyzer ****************************************************** * * Caller Hash Malloc Free Diff demo.c:12 main 3b55b4b1 1 0 1 demo.c:14 main efdff78 3 1 2 demo.c:14 main efe0001 3 1 2 demo.c:14 main efe0103 3 1 2 demo.c:14 main efe0205 3 1 2 demo.c:14 main efdfe76 3 1 2 demo.c:25 main 7be5e67c 1 1 0 demo.c:25 main 7be5e807 1 1 0 demo.c:25 main 7be5e992 1 1 0 demo.c:25 main 66a46b9a 1 1 0 demo.c:25 main 66a46d9e 1 1 0 demo.c:25 main 66a46f29 1 1 0 demo.c:25 main 66a4ae9f 1 1 0 demo.c:30 main 52662d45 10 4 6 demo.c:30 main 52662ed0 10 4 6 demo.c:30 main 2a47da54 10 5 5 demo.c:30 main 2a47dc58 10 3 7 demo.c:30 main 2a47dde3 10 4 6 demo.c:30 main 2a481d59 10 5 5 demo.c:30 main 2a481ee4 10 5 5 demo.c:30 main 2a48206f 10 4 6 demo.c:30 main 2a48605e 10 4 6 demo.c:30 main 2a4861e9 10 4 6 demo.c:30 main 2a486374 10 4 6 demo.c:30 main 2a48a2ea 10 6 4 demo.c:30 main 2a48a475 10 4 6 demo.c:30 main 2a48a679 10 4 6 demo.c:30 main 2a48e5ef 10 4 6 demo.c:30 main 52662bba 9 4 5 *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MLA Verbose %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%* >1 Caller Size Malloc Free Diff demo.c:12 main 8 1 0 1 *--------------------------------------------------------------------------------------------------------------------------------* >2 Caller Size Malloc Free Diff demo.c:14 main 32 3 1 2 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (32)B - [3] demo.c:17 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >3 Caller Size Malloc Free Diff demo.c:14 main 48 3 1 2 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (48)B - [3] demo.c:17 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >4 Caller Size Malloc Free Diff demo.c:14 main 64 3 1 2 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (64)B - [3] demo.c:17 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >5 Caller Size Malloc Free Diff demo.c:14 main 80 3 1 2 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (80)B - [3] demo.c:17 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >6 Caller Size Malloc Free Diff demo.c:14 main 16 3 1 2 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (16)B - [3] demo.c:17 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >7 Caller Size Malloc Free Diff demo.c:25 main 32 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (32)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >8 Caller Size Malloc Free Diff demo.c:25 main 64 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (64)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >9 Caller Size Malloc Free Diff demo.c:25 main 96 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (96)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >10 Caller Size Malloc Free Diff demo.c:25 main 128 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (128)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >11 Caller Size Malloc Free Diff demo.c:25 main 160 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (160)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >12 Caller Size Malloc Free Diff demo.c:25 main 192 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (192)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >13 Caller Size Malloc Free Diff demo.c:25 main 224 1 1 0 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (224)B - [1] demo.c:27 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >14 Caller Size Malloc Free Diff demo.c:30 main 64 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (64)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >15 Caller Size Malloc Free Diff demo.c:30 main 96 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (96)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >16 Caller Size Malloc Free Diff demo.c:30 main 128 10 5 5 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (128)B - [10] demo.c:33 main - [4] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >17 Caller Size Malloc Free Diff demo.c:30 main 160 10 3 7 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (160)B - [10] demo.c:33 main - [3] | *--------------------------------------------------------------------------------------------------------------------------------* >18 Caller Size Malloc Free Diff demo.c:30 main 192 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (192)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >19 Caller Size Malloc Free Diff demo.c:30 main 224 10 5 5 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (224)B - [10] demo.c:33 main - [4] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >20 Caller Size Malloc Free Diff demo.c:30 main 256 10 5 5 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (256)B - [10] demo.c:36 main - [2] | | 2. demo.c:33 main - [3] | *--------------------------------------------------------------------------------------------------------------------------------* >21 Caller Size Malloc Free Diff demo.c:30 main 288 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (288)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >22 Caller Size Malloc Free Diff demo.c:30 main 320 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (320)B - [10] demo.c:33 main - [4] | *--------------------------------------------------------------------------------------------------------------------------------* >23 Caller Size Malloc Free Diff demo.c:30 main 352 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (352)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >24 Caller Size Malloc Free Diff demo.c:30 main 384 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (384)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >25 Caller Size Malloc Free Diff demo.c:30 main 416 10 6 4 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (416)B - [10] demo.c:33 main - [4] | | 2. demo.c:36 main - [2] | *--------------------------------------------------------------------------------------------------------------------------------* >26 Caller Size Malloc Free Diff demo.c:30 main 448 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (448)B - [10] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* >27 Caller Size Malloc Free Diff demo.c:30 main 480 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (480)B - [10] demo.c:36 main - [1] | | 2. demo.c:33 main - [3] | *--------------------------------------------------------------------------------------------------------------------------------* >28 Caller Size Malloc Free Diff demo.c:30 main 512 10 4 6 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (512)B - [10] demo.c:33 main - [4] | *--------------------------------------------------------------------------------------------------------------------------------* >29 Caller Size Malloc Free Diff demo.c:30 main 32 9 4 5 *--------------------------------------------------------------------------------------------------------------------------------* |Verbose: malloc free | | 1. (32)B - [9] demo.c:33 main - [3] | | 2. demo.c:36 main - [1] | *--------------------------------------------------------------------------------------------------------------------------------* ``` Work Together ------- `issue` Welcome to use and feedback