質問

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