summaryrefslogtreecommitdiff
path: root/cgpt/cgpt_prioritize.c
diff options
context:
space:
mode:
authorFletcher Woodruff <fletcherw@chromium.org>2019-03-11 13:33:40 -0600
committerchrome-bot <chrome-bot@chromium.org>2019-03-13 21:05:07 -0700
commit2f6381ec0360b96ba836168b4635ceaaf4aff262 (patch)
treeba73fe92a449b3a965d143aed468e491e8914154 /cgpt/cgpt_prioritize.c
parent3bfaab121cbafbd5c6d57004df6784866b8de5de (diff)
downloadvboot-2f6381ec0360b96ba836168b4635ceaaf4aff262.tar.gz
Fix memory leaks in cgpt
DriveOpen mallocs a couple of buffers, but DriveClose only freed them if a particular flag was passed causing GptSave to be called. Move the free calls out of GptSave so that the buffers are always freed, and add DriveClose calls to a couple of cgpt functions that are missing them. BUG=chromium:940543 TEST=precq passes, manual testing with cgpt/valgrind shows that memory leaks for cgpt find, show are fixed. BRANCH=none Change-Id: I58aeddfa6b8b4715ba4f8e064e95a660371a01c9 Reviewed-on: https://chromium-review.googlesource.com/1516413 Commit-Ready: Fletcher Woodruff <fletcherw@chromium.org> Tested-by: Fletcher Woodruff <fletcherw@chromium.org> Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'cgpt/cgpt_prioritize.c')
-rw-r--r--cgpt/cgpt_prioritize.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/cgpt/cgpt_prioritize.c b/cgpt/cgpt_prioritize.c
index c4e812c2..b59005f7 100644
--- a/cgpt/cgpt_prioritize.c
+++ b/cgpt/cgpt_prioritize.c
@@ -113,11 +113,12 @@ int CgptPrioritize(CgptPrioritizeParams *params) {
if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
Error("GptSanityCheck() returned %d: %s\n",
gpt_retval, GptError(gpt_retval));
- return CGPT_FAILED;
+ goto bad;
}
if (CGPT_OK != CheckValid(&drive)) {
Error("please run 'cgpt repair' before reordering the priority.\n");
+ (void) DriveClose(&drive, 0);
return CGPT_OK;
}