Mr-Dave/motion — pull request #41 by aklomp (2014-10-06 21:51:37+00:00)
Title: Fix incorrect sizeof() calculations in malloc and memset

The proper idiom for calculating an image's memory size from a pointer using `sizeof()` is:

ptr = malloc(width * height * sizeof(*ptr));

The `sizeof()` dereferences the pointer's type, and allocates enough memory to store an image's worth of elements of that type. However, Motion was occasionally using this pattern:

ptr = malloc(width * height * sizeof(ptr));

Not dereferencing the pointer, this uses the storage size of the pointer itself, not its target type, for the calculation. While this is probably not immediately harmful since pointers tend to be large, it is incorrect. This pull request fixes a number of these issues.