commit e173ee1c548a72a6be303a0c241dc62fb1891666
Author: Daniele Forsi <df...@sr...>
Date: Mon Mar 26 23:15:31 2012 +0200
Fix possible memleaks found by cppcheck
Actually g_strdup(NULL) returns NULL so it wouldn't leak.
Fixes:
[src/itdb_itunesdb.c:426]: (error) Memory leak: good_path
[src/itdb_itunesdb.c:982]: (error) Memory leak: playcount
[tools/udev-backend.c:262]: (error) Memory leak: backend
src/itdb_itunesdb.c | 6 ++++--
tools/udev-backend.c | 10 +++++-----
2 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/src/itdb_itunesdb.c b/src/itdb_itunesdb.c
index 34d5b80..4046a50 100644
--- a/src/itdb_itunesdb.c
+++ b/src/itdb_itunesdb.c
@@ -420,10 +420,11 @@ static void itdb_fsync (void)
gchar * itdb_resolve_path (const gchar *root,
const gchar * const * components)
{
- gchar *good_path = g_strdup(root);
+ gchar *good_path;
guint32 i;
if (!root) return NULL;
+ good_path = g_strdup (root);
for(i = 0 ; components[i] ; i++) {
GDir *cur_dir;
@@ -975,12 +976,13 @@ static gboolean playcounts_read (FImport *fimp, FContents *cts)
for (i=0; i<entry_num; ++i)
{
guint32 mac_time;
- struct playcount *playcount = g_new0 (struct playcount, 1);
+ struct playcount *playcount;
glong seek = header_length + i*entry_length;
check_seek (cts, seek, entry_length);
CHECK_ERROR (fimp, FALSE);
+ playcount = g_new0 (struct playcount, 1);
playcounts = g_list_prepend (playcounts, playcount);
playcount->playcount = get32lint (cts, seek);
mac_time = get32lint (cts, seek+4);
diff --git a/tools/udev-backend.c b/tools/udev-backend.c
index e6103b0..80c35d8 100644
--- a/tools/udev-backend.c
+++ b/tools/udev-backend.c
@@ -252,16 +252,16 @@ int main (int argc, char **argv)
}
g_type_init ();
- backend = udev_backend_new ();
- if (backend == NULL) {
- return -1;
- }
-
fstype = g_getenv ("ID_FS_TYPE");
if (fstype == NULL) {
return -1;
}
+ backend = udev_backend_new ();
+ if (backend == NULL) {
+ return -1;
+ }
+
usb_bus_number = atoi (argv[2]);
usb_dev_number = atoi (argv[3]);
|