Fix handling if applying patch is failed

Change-Id: Iecf6e9e864e53d62fc75bbd5496602aa15d7904f