Fix leaks in test code

Change-Id: I435fcfd6d10875565b543ea76fa8bfbf52e5f5d0
Fix memory leak

Change-Id: I0e5c3af0504f3090a5db7692c6bfb1d33b3aa81f
Fix memory leak

Change-Id: I70522657f968ed4f84e9447dd999d8be746fc973
Fix memory leak

Change-Id: Ia9176826b89b947408230bf65db26a83f269c845
Fix leak

Change-Id: Ie1c0cb94fae8b227f7ef66df5a2a2ca3f0738897
Fix memory leak in test code

Change-Id: I318878b3fa883eebbc081a6faf6a594dad2c6e26
Avoid undefined left shift of negative integer

Change-Id: Ib857f7c802b4ce65ec352b67e6acde59965c893a