daemon: fixed memory leak and array bounds check fail

3 jobs for pull-42
in 2 minutes and 54 seconds and was queued for 3 seconds