char *string1 = strdup(data.c_str());
// do stuff with string1
free(string1);
SHA1((unsigned char*)&string1, strlen(string1), (unsigned char*)&digest);
There’s your error.
- You created string1
- You used it
- You freed it
- You used it again
Don’t free what you still need to use.
In addition to that:
SHA1((unsigned char*)&string1, strlen(string1), (unsigned char*)&digest);
What you’re doing here is passing the address of char* string1
converted to an unsigned char*
. What you want to do is pass string1
instead of &string1
. The same applies to digest
.
1
solved C++ Sha1 issue with using char *