use calloc instead of malloc/memset pair and check returns where it made sense. Also use NULL to initialize a pointer not 0 for clarity