cgpt repair: fix segfault which occurs when one of the headers is bad

When one of GPT headers is invalid the corresponding partition table
is not loaded and corresponding pointers in GptData are NULL.
GptRepair will try to memcpy one entries table to another which
results in SIGSEGV.

This change fixes it by freeing and then reallocating bad copy of
partition table. This potentially fixes problems which would occur
if two tables have different size.

Change that initially introduced this problem by not always allocating

TEST="cgpt repair" works where it previously didn't
TEST=make runtests

Change-Id: Ibb2fcf33faa5ba157b0865d04c90ee3f26eee113
Reviewed-by: Randall Spangler <>
Commit-Queue: Andrey Ulanov <>
Tested-by: Andrey Ulanov <>
4 files changed