From 517ed633c254b8bbf071ec69b1e167af5fa53e75 Mon Sep 17 00:00:00 2001 From: Chris Morin Date: Thu, 4 Jan 2018 14:46:01 -0800 Subject: [PATCH] fs_mgr: fix memory leak The fstab struct wasn't properly being freed. Test: Ensure a user of fs_mgr (vold) runs without errors. Change-Id: I4dcb8ae2ab3e831fbdb13372eb31a67a5d9fb735 --- fs_mgr/fs_mgr_fstab.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs_mgr/fs_mgr_fstab.cpp b/fs_mgr/fs_mgr_fstab.cpp index 34afed1a4..d913af039 100644 --- a/fs_mgr/fs_mgr_fstab.cpp +++ b/fs_mgr/fs_mgr_fstab.cpp @@ -654,12 +654,13 @@ static struct fstab *in_place_merge(struct fstab *a, struct fstab *b) } for (int i = a->num_entries, j = 0; i < total_entries; i++, j++) { - // copy the pointer directly *without* malloc and memcpy + // Copy the structs by assignment. a->recs[i] = b->recs[j]; } - // Frees up b, but don't free b->recs[X] to make sure they are - // accessible through a->recs[X]. + // We can't call fs_mgr_free_fstab because a->recs still references the + // memory allocated by strdup. + free(b->recs); free(b->fstab_filename); free(b);