There are a handful of issues with this code.
char *pu1_out_buffer = malloc(length);
pu1_out_buffer = datafromfile(FILE_PATH) // initialized with some data , not important
That leaks the original malloc
.
[self function1:pu1_out_buffer
rgb_buffer:(UWORD16 *)[rgbData bytes]
…]
That method should be something like: function1:rgbBuffer:
...
As for the crash, it is most likely for the reason Martin cites. If you have ARC enabled, you are grabbing an interior pointer from the NSMutableData
instance. ARC can't associate the return value of bytes
with the original data, assumes the data object is no longer being used, and releases it.
To fix, add:
[rgbData bytes]
right before return outUIImage;
. That will let ARC know that the object is in use through the duration of the function2:width:height:stride:
call.