diff --git a/tools/rkcommon.c b/tools/rkcommon.c
index fd95abc79aed5533d578e93a7e9d2a5ba0ca1074..a583c0caa0d5d098eb25079f5fe1efb1808e3217 100644
--- a/tools/rkcommon.c
+++ b/tools/rkcommon.c
@@ -380,8 +380,9 @@ int rkcommon_vrec_header(struct image_tool_params *params,
 
 	/* Allocate, clear and install the header */
 	tparams->hdr = malloc(tparams->header_size);
+	if (!tparams->hdr)
+		return -ENOMEM;
 	memset(tparams->hdr, 0, tparams->header_size);
-	tparams->header_size = tparams->header_size;
 
 	/*
 	 * If someone passed in 0 for the alignment, we'd better handle