fix parsing of cmdline args

Change-Id: I4005c08d4163d5d26f227e01c2520379f717343a
avoid memory leak

Change-Id: I9ac97c4e5c7b01b5e05cb1132c0d245f5843799e