Advertisement
AneMou

C - Realloc Memory Leak

May 16th, 2024 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | Source Code | 0 0
  1. /* ... */
  2.  
  3. // This function adds an item to a list
  4. void addToList(struct list *myList, int item) {
  5.    
  6.     // If the list is full then resize the memory to fit 10 more items
  7.     if (myList->numItems == myList->size) {
  8.         myList->size += 10;
  9.         myList->data = realloc( myList->data, myList->size * sizeof(int) );
  10.     }
  11.    
  12.     /* ... */
  13.  
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement