[Adium-devl] [Adium-svn] rev 22205 - trunk/Plugins/Purple Service

Peter Hosey boredzo at gmail.com
Wed Jan 9 00:19:36 UTC 2008


On Jan 08, 2008, at 16:05:17, evands at adiumx.com wrote:
> Documentation of `SecCertificateGetData()` says that we should  
> malloc space for its return data, so we should do so.

Er, no, it doesn't say that. It says we should allocate space for it[1]:

> You must allocate the space for a CSSM_DATA structure before  
> calling this function.

The previous code did that with the stack.

One of Apple's own samples does the same thing[2]:

>   CSSM_DATA certData;
>   CFIndex i;
>
>   if(peerCerts == NULL) {
>     return;
>   }
>   numCerts = CFArrayGetCount(peerCerts);
>   for(i=0; i<numCerts; i++) {
>     certRef = (SecCertificateRef)CFArrayGetValueAtIndex(peerCerts, i);
>     ortn = SecCertificateGetData(certRef, &certData);
>>   }

Have you seen some other documentation that gets more specific that  
we should use malloc? Alternatively, did changing it to malloc fix a  
bug?

If not, I think we should put it back the way it was. Any time you  
malloc something, you risk forgetting to free it later (in this case,  
if we add more error cases to bail out for*). We shouldn't assume  
that risk unnecessarily.

* That's also an argument for having only one exit from this huge  
method, but that's another issue.

[1]: <http://developer.apple.com/documentation/Security/Reference/ 
certifkeytrustservices/Reference/reference.html#//apple_ref/c/func/ 
SecCertificateGetData>
[2]: <http://developer.apple.com/samplecode/SSLSample/listing2.html>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 186 bytes
Desc: This is a digitally signed message part
URL: <http://adium.im/pipermail/devel_adium.im/attachments/20080108/7bc89800/attachment.sig>


More information about the devel mailing list