aai: initialize vars
- fix mem-leaks
- checking array != NULL
- incorrect usage of sizeof()