void x( )
{
strcpy(a, strdup(p) );
}
(error) Allocation with strdup, strcpy doesn’t release it
Can anyone tell me what’s wrong with above statement and why I am getting this error?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem is that you are leaking memory. The call to
strdupallocates memory which is not freed. The pointer to the memory that is passed tostrcpyis never saved anywhere and the compiler can therefore prove that it is leaked.I’m not sure what you are trying to do since
strdupperforms both allocation and copying, the call tostrcpyseems superfluous.