Discussion:
[PATCH] fix two memleaks
Johannes Weißl
2011-05-05 01:19:47 UTC
Permalink
---
cache.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/cache.c b/cache.c
index c5a251a..3a1e608 100644
--- a/cache.c
+++ b/cache.c
@@ -358,7 +358,7 @@ int cache_close(void)
GBUF(buf);
struct track_info **tis;
unsigned int offset;
- int i, fd;
+ int i, fd, rc;
char *tmp;

if (!new && !removed)
@@ -366,8 +366,10 @@ int cache_close(void)

tmp = xstrjoin(cmus_config_dir, "/cache.tmp");
fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0666);
- if (fd < 0)
+ if (fd < 0) {
+ free(tmp);
return -1;
+ }

tis = get_track_infos();

@@ -378,11 +380,12 @@ int cache_close(void)
write_ti(fd, &buf, tis[i], &offset);
flush_buffer(fd, &buf);
gbuf_free(&buf);
+ free(tis);

close(fd);
- if (rename(tmp, cache_filename))
- return -1;
- return 0;
+ rc = rename(tmp, cache_filename);
+ free(tmp);
+ return rc;
}

static struct track_info *ip_get_ti(const char *filename)
--
1.7.5
Gregory Petrosyan
2011-05-05 13:11:43 UTC
Permalink
Post by Johannes Weißl
---
cache.c | 13 ++++++++-----
1 files changed, 8 insertions(+), 5 deletions(-)
Nice catch, merged -- thanks again!

Gregory

Loading...