Linux - C language Memory Tracing Program
Budget: $10 – $30 USD
I am working on a project to demonstrate memory management and avoid memory leaks in C which I have some parts of the program already. I would like to Implement a program in C that reads all lines from an input file into an array of type char ** . Then, my thinking is to Initialize the array memory with malloc to an initial size, which by using realloc, it would be possible to expand the array if the initial size turns out not to be big enough for the lines in the input file. We can consider that the input file is more than at least 100 lines.
For the implementation, I would want to store each line in a linked list where a node contains the line as a string (char *) and index number.
Also, at the end I would like to have to implement a recursive function PrintNodes that prints out the content of all nodes in the linked list; printing just the line and index number are sufficient. Call PrintNodes to ensure the linked list has the correct content. Implement tracing of memory consumption. Use a stack holding the function names and print the memory consumed whenever memory is allocated, reallocated or freed. The tracing should print messages describing the memory management and usage in each function. The allocation and deallocation for the char ** array and the linked list should make use of memory tracing in order to print messages describing the memory management and usage.
The parent process should redirect the stdout to a log file named track.out For this part I would want to use dup2 for the purpose of redirecting stdout (fd1) to the track.out file. And then, the dup2() call will replace the file descriptor STDOUT_FILENO with the opened file for track.out.
At the end, the purpose of this self project is to ensure there are no memory leaks while the code should work with an input file of more than 100 lines.
For the implementation, I would want to store each line in a linked list where a node contains the line as a string (char *) and index number.
Also, at the end I would like to have to implement a recursive function PrintNodes that prints out the content of all nodes in the linked list; printing just the line and index number are sufficient. Call PrintNodes to ensure the linked list has the correct content. Implement tracing of memory consumption. Use a stack holding the function names and print the memory consumed whenever memory is allocated, reallocated or freed. The tracing should print messages describing the memory management and usage in each function. The allocation and deallocation for the char ** array and the linked list should make use of memory tracing in order to print messages describing the memory management and usage.
The parent process should redirect the stdout to a log file named track.out For this part I would want to use dup2 for the purpose of redirecting stdout (fd1) to the track.out file. And then, the dup2() call will replace the file descriptor STDOUT_FILENO with the opened file for track.out.
At the end, the purpose of this self project is to ensure there are no memory leaks while the code should work with an input file of more than 100 lines.