So basically, in tmux/grid.c - you want it to look like this: /* Destroy grid. */ void grid_destroy(struct grid *gd) { struct grid_line *gl; u_int yy; for (yy = 0; yy < gd->hsize + gd->sy; yy++) { gl = &gd->linedata[yy]; free(gl->celldata); } free(gd->linedata); free(gd); malloc_trim(0); }