NULL-checks before free()
W.C.A. Wijngaards
wouter at nlnetlabs.nl
Tue Jan 5 12:39:47 UTC 2016
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Hi Michael,
On 11/12/15 21:02, Michael McConville wrote:
> W.C.A. Wijngaards via Unbound-users wrote:
>> On 10/12/15 01:35, Michael McConville via Unbound-users wrote:
>>> I thought I'd send a few quick cleanup diffs if people are
>>> interested. I'm an OpenBSD dev and we include Unbound in our
>>> base system, so these are just things I've noticed over the
>>> past few months.
>>>
>>> Here's the first one. POSIX specifies that free() is
>>> NULL-safe. All modern and almost all prehistoric platforms
>>> conform to this, and most codebases already assume it.
>>
>> Thank for you for your patch, I have included it in the source.
>
> Thanks!
>
> Here's another: just removing a bunch of malloc casts.
I can see that was a lot of work, but the casts are necessary.
Otherwise, an assignment from an incompatible pointer type warning is
printed on some systems. Others allow it, but it is not universal.
Best regards, Wouter
>
> @@ -402,7 +402,7 @@ sizeof(time_t))* num; for(i=0; i<num; i++) s +=
> d->rr_len[i]; - ad = (struct packed_rrset_data*)malloc(s); + ad =
> malloc(s); if(!ad) { log_warn("error out of memory");
> ub_packed_rrset_parsedelete(ak, &worker->alloc); @@ -272,7 +272,7
> @@ static struct ta_key* anchor_new_ta_key(uint8_t* rdata, size_t
> rdata_len, uint16_t type) { - struct ta_key* k = (struct
> ta_key*)malloc(sizeof(*k)); + struct ta_key* k =
> malloc(sizeof(*k)); if(!k) return NULL; memset(k, 0, sizeof(*k));
> @@ -854,8 +854,7 @@ static struct ub_packed_rrset_key*
> assemble_it(struct trust_anchor* ta, size_t num, uint16_t type) { -
> struct ub_packed_rrset_key* pkey = (struct ub_packed_rrset_key*) -
> malloc(sizeof(*pkey)); + struct ub_packed_rrset_key* pkey =
> malloc(sizeof(*pkey)); struct packed_rrset_data* pd; struct ta_key*
> tk; size_t i;
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQIcBAEBCAAGBQJWi7mTAAoJEJ9vHC1+BF+NzfIP/R46ytCvjAlj7gxkbWqkj5s4
xuv/yUjJza4anOSdD/p6IckNsGz2I1Ggg/sTnA3227WzNUsQkOz9i9hLhQZpOMGA
t7zyiI+pqTm75OnZFBxdXRuFbj6B9iMNL3UWDyqupqc9nR3Y+Tcun1mwjfAOKUgV
jvZuAjTUE1sv24LkHLfe0nvPS7EMbAbWaFI9nUshEjsfridzdsydcJOWT/l9eblJ
AsZDgZ6OijAUwI/wYVSprLixXRra1J8WH/nJZgXp0o8R/NHFAlP97F3O5bAunnv6
tUegeHPB9jGMoBO/OlZrt4K1RrvimL5pmpFbNvsI8AJxgB7nct1vIdVFRg/4g4BN
H20DUXto6sTlh4aoze53FqnlcqvWMV0ojm0ULi91FSTh02K+eho4A+1QoQzumA9s
5GkH2vgIdPa4EqTD2m4NkPD4252QLuvp78THqs58aHKcBlcesirIklpdB/qxP+d6
2JbP/Vbtslb77+Q/EXy9o1sfF17eZiThJhqen8HUp88BITAALzjywc/cvDZh1J6n
6MQbgbqks0emwXnqyyP1r1X4zRRxXP4XHjU4+vg7+tYdEnx53RDtDlU5OqYlPPSD
RVRGHEp+SYtIxY8IYSYQ6gk+u/CzMBIjY5sIgFSUwGNHwIpo+v3VYzJCiK5AQQUE
Z6apLVV1Kx4HgMGyIwdu
=m7K3
-----END PGP SIGNATURE-----
More information about the Unbound-users
mailing list