Use calloc(n, size) instead of malloc(n * size)