Question: In Linux c program, Although it appears to run correctly, there is a memory leak within the loop that will eventually cause a problem if

In Linux c program, Although it appears to run correctly, there is a memory leak within the loop that will eventually cause a problem if the loop is executed a sufficient number of times. Please fix the code.

#include #include #include #define SIZE 16 int main() { char *data1, *data2; int i; do { data1 = malloc (SIZE); printf ("Please input your username: "); scanf ("%s", data1); if (!strcmp (data1, "quit")) break; data2 = malloc (SIZE); for (i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!