This is a second, more complex fix for this routine. There is a multiple resource leaks and invalid VirtualFreeEx call. Note that truncated pointers in various printfs are still in place as I don't know was it intended or not.
Expression if (bStatus == NULL) is always false because it was checked before. Thus error handling block never executed. Considering wrong valuable used.