Fix memory leak in mtp-filetree example.
Signed-off-by: Lei Zhang <thestig@google.com>
Signed-off-by: Linus Walleij <triad@df.lth.se>
diff --git a/examples/filetree.c b/examples/filetree.c
index 6d6ed81..234d093 100644
--- a/examples/filetree.c
+++ b/examples/filetree.c
@@ -49,8 +49,10 @@
}
/* Iterate over the filelisting */
- for (file = files; file != NULL; file = file->next) {
+ file = files;
+ while (file != NULL) {
int i;
+ LIBMTP_file_t *oldfile;
/* Indent */
for (i = 0; i < depth; i++) {
@@ -60,6 +62,10 @@
if (file->filetype == LIBMTP_FILETYPE_FOLDER) {
recursive_file_tree(device, storage, file->item_id, depth+2);
}
+
+ oldfile = file;
+ file = file->next;
+ LIBMTP_destroy_file_t(oldfile);
}
}