xxyzz / ostep-hw

Operating Systems: Three Easy Pieces(OSTEP) homework and project solutions
GNU General Public License v3.0
780 stars 181 forks source link

fix memory leaks and other things in 29/btree.c #20

Open sci-42ver opened 1 year ago

sci-42ver commented 1 year ago

I used the valgrind to fix the memory leak errors in the code. Hope this can help the future readers understand the book. I also did the following:

  1. Use the explicit initialization char *s = calloc(1024 * sizeof(char),1024); to ensure s not having weird characters which will influence strcat(s, indent);.
  2. remove if (j > 0) to give one whole Btree graph.
  3. add free_node function to ensure no crash due to the memory leak with many iterations.