commit 093d0682d14384b3ab8cb114d211c42dd4a03445 parent c68f913e25b52cb755d84702c0ae8f047f30d34a Author: sin <sin@2f30.org> Date: Fri, 2 Jan 2015 15:53:47 +0000 Fix memory leak + size calculations when removing an element from the playlist Diffstat:
M | playlist.c | | | 12 | ++++++++---- |
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/playlist.c b/playlist.c @@ -42,14 +42,18 @@ rmplaylist(int id) Song *s; int i; - for (i = 0; i < playlist.nsongs; i++) - if (playlist.songs[i]->id == id) + for (i = 0; i < playlist.nsongs; i++) { + s = playlist.songs[i]; + if (s->id == id) break; + } if (i == playlist.nsongs) return -1; + + free(s); s = getnextsong(); - memmove(&playlist.songs[i], &playlist.songs[i+1], - (playlist.nsongs - i - 1) * sizeof(*playlist.songs[i])); + memmove(&playlist.songs[i], &playlist.songs[i + 1], + (playlist.nsongs - i - 1) * sizeof(playlist.songs[i])); putcursong(s); playlist.nsongs--; return 0;