Still, instead of doing this:

```
void *targetBuf = NULL;
...
oChunk = chunk_new(id, chunkNumber, &targetBuf, (void*)data_ptr, chunkLen, flags );
memAllocated = targetBuf != data_ptr;
...

if( memAllocated ) {
  bson_free( targetBuf );
}
```

can't you handle it right in `chunk_new`?
```
...
oChunk = chunk_new(id, chunkNumber, (void*)data_ptr, chunkLen, flags );
...

bson * chunk_new (bson_oid_t id, int chunkNumber, void* srcData, size_t len, int flags ) {
  if( preProcessChunk( dataBuf, &dataBufLen, srcData, len, flags) != 0 ) {
    return NULL;
  }
...
if (targetBuf != data_ptr)
    bson_free( targetBuf );
...
}
```