coverity scans: Uninitialized scalar field errors

Addressed uninitialized scalar field errors.
coverity scan: Untrusted loop bound

Fix issue error for loop bounds.
coverity scans: fix Unrecoverable parse warning

These errors cause distractions, even though they are low priority.
coverity scan: fix leaking dir

Close dir before returning on error exit path, fixes leak detected
by coverity scan.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
coverity scan: fix memory leak

delete trip_ptr, fixes memory leak detected by coverity scan

Signed-off-by: Colin Ian King <colin.king@canonical.com>