Philip Prindeville wrote:
Rich Megginson wrote:
Philip Prindeville wrote:
Rich Megginson wrote:
https://bugzilla.mozilla.org/show_bug.cgi?id=323374
Files: https://bugzilla.mozilla.org/attachment.cgi?id=208698
Diffs: https://bugzilla.mozilla.org/attachment.cgi?id=208699
1) I'm pretty sure the reference to socket should be fd instead. I
don't know why it compiled with socket in there . . . note to self:
read compiler warnings . . .
2) The cert returned by SSL_PeerCertificate is "dup"ed, so we need
to call CERT_DestroyCertificate to release it otherwise we'll leak
references.
3) The hostname returned by SSL_RevealURL is strduped and must be
freed.
Looking at:
+ if (hostname) {
+ PL_strfree(hostname);
+ }
Isn't PL_strfree() -- which calls free() -- NULL safe?
No - see http://lxr.mozilla.org/nspr/ident?i=PL_strfree
Yes, exactly:
PR_IMPLEMENT <http://lxr.mozilla.org/nspr/ident?i=PR_IMPLEMENT>(void)
PL_strfree <http://lxr.mozilla.org/nspr/ident?i=PL_strfree>(char *s
<http://lxr.mozilla.org/nspr/ident?i=s>)
{
free <http://lxr.mozilla.org/nspr/ident?i=free>(s
<http://lxr.mozilla.org/nspr/ident?i=s>);
}
Now reading the man page for free(), we see:
free() frees the memory space pointed to by ptr, which must
have been
returned by a previous call to malloc(), calloc() or
realloc(). Oth-
erwise, or if free(ptr) has already been called before,
undefined
behaviour occurs. If ptr is NULL, no operation is performed.
Hmm - you're right. I've checked HP/ux 11.23, Solaris 9, and various
versions of RHEL and Fedora Core, and they all say that. Is this the
behavior of POSIX free()? Or is there some other standard that covers
the behavior of free() (C99)? Our code is full of defensive programming
against free'ing NULL. I know in years past free(NULL) used to cause a
segfault on some platforms, or abort on others. Do you know if free()
behaves this way on Windows and Mac?
-Philip
So when you check the pointer for non-NULL, you're duplicating
code inside of free().
-Philip
_______________________________________________
dev-tech-ldap mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-ldap