I have a function defined in a library that I reference with -lcrypto
for gcc
This is the definition from the header file
unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md);
The definition https://github.com/openssl/openssl/blob/master/crypto/sha/sha256.c#L63
The function takes a char pointer as the third argument, fills it with results, and returns it.
If I passed a NULL as that third parameter, the function creates a pointer and ignores it, then returns it.
I know that in order to return a pointer it must be allocated on the heap, thus a malloc
must have been called.
But when I call this function
unsigned char * hash = SHA256((char*) &bh, sizeof(struct DIGEST), NULL);
I expect hash
to be a pointer to a memory address so I run free(hash)
and then it fails.
free(): invalid pointer: 0x00007f301f7958a0 ***
Aborted (core dumped)
Which of assumptions are wrong?