I have the following function in a class.
uint8_t* EncryptRSA(uint8_t* pkgbuf, int& size/*in, out*/);
Memory for pkgbuf is allocated outside the function, before the function call.
The second parameter has the size of pkgbuf.
Inside the function I allocate fresh memory for the return value of the function as:
uint8_t* retbuf = new BYTE[NEWSIZE];
I leave the responsibility of cleaning up the memory allocated for pkgbuf to the caller of the function EncryptRSA.
Is it better to reallocate memory to the pointer pkgbuf inside the function with a return type of void.
I am avoiding memory reallocation as there seems NO c++ way to reallocate memory. Also, if for some reason the caller would still like to use pkgbuf outside the function it will become unavailable.
Is there any better way of doing this and why? Tnx