Suppose a method from a COM interface returns BSTR value. Am I right in my opinion that I must free it?
The code example at http://msdn.microsoft.com/en-us/library/aa365382(VS.85).aspx does not do that.
Who’s wrong?
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 MSDN sample is wrong. The caller frees out and in/out bstrs. If it’s in/out you have to pass in null or a valid bstr. If it’s out only, it doesn’t have to be initialized.
It’s not super clear from msdn’s com allocation rules, but the client stub allocates the memory on out values so from the caller’s point of view the server did. Who else can free it but the caller?