100x100x4 = 40000, why you indeed need that much memory for it.
For bufsize, you often need to round the width up to 4 (but that should be in the documentation).
bufsize = ROUNDUP_TO_4(width) * height * Bpp;
where Bpp = Bytes per pixel, and ROUNDUP_TO_4 could be
#define ROUNDUP_TO_4(x) (((x)+3)&~3)