Does the following code contain a memory leak of the first three characters in the string?
char * str = (char*)malloc(21 * sizeof(char));
strcpy(str, "01234567890123456879");
str = str + 3;
free(str);
Thanks.
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.
Its worse than a leak, you are not supposed to call
freewith a pointer not returned frommalloc(orrealloc/calloc). You could get a leak, or a crash, or who knows what else… What you do is undefined behavior.