문제

After allocating and initializing a char* and copying a data for it

char * uri= new char [strlen(realm) + strlen("sip:") +1]();
strcpy(uri, "sip:"); 
strcat(uri, realm);

I pass this char* to pj_str(char*) function. This function convert the char* to pj_str_t struct that contains a pointer to the buffer and its length.

Then the function continue its logic and uses the uri pj_str.

Before the function return, it's supposed to deallocate *uri. When doing this line of code the first two characters contain an octal garbage data else it contains the expected data.

delete [] uri;

What is the problem?!

도움이 되었습니까?

해결책

Isn't it enough to do

delete [] uri;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top