diff options
author | Hakan Olsson <ho@cvs.openbsd.org> | 2001-08-16 18:16:44 +0000 |
---|---|---|
committer | Hakan Olsson <ho@cvs.openbsd.org> | 2001-08-16 18:16:44 +0000 |
commit | 61852bcd4db821cd3bfda8b182f46a25f543f0d4 (patch) | |
tree | c6ee117cf59d833a29b78bfcc694eb478d05cd0a /lib/libc | |
parent | 7727e8918bc08470bce72e3d05b91a8ecce0dd27 (diff) |
Use calloc() to allocate response data. Be more careful when freeing
memory. jakob@ ok.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/getrrsetbyname.c | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/libc/net/getrrsetbyname.c b/lib/libc/net/getrrsetbyname.c index bc4b88bbbdf..87ae8fc229e 100644 --- a/lib/libc/net/getrrsetbyname.c +++ b/lib/libc/net/getrrsetbyname.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getrrsetbyname.c,v 1.3 2001/08/07 10:16:00 deraadt Exp $ */ +/* $OpenBSD: getrrsetbyname.c,v 1.4 2001/08/16 18:16:43 ho Exp $ */ /* * Copyright (c) 2001 Jakob Schlyter. All rights reserved. @@ -253,20 +253,26 @@ freerrset(struct rrsetinfo *rrset) if (rrset == NULL) return; - for (i = 0; i < rrset->rri_nrdatas; i++) { - if (rrset->rri_rdatas[i].rdi_data == NULL) - break; - free(rrset->rri_rdatas[i].rdi_data); + if (rrset->rri_rdatas) { + for (i = 0; i < rrset->rri_nrdatas; i++) { + if (rrset->rri_rdatas[i].rdi_data == NULL) + break; + free(rrset->rri_rdatas[i].rdi_data); + } + free(rrset->rri_rdatas); } - free(rrset->rri_rdatas); - for (i = 0; i < rrset->rri_nsigs; i++) { - if (rrset->rri_sigs[i].rdi_data == NULL) - break; - free(rrset->rri_sigs[i].rdi_data); + if (rrset->rri_sigs) { + for (i = 0; i < rrset->rri_nsigs; i++) { + if (rrset->rri_sigs[i].rdi_data == NULL) + break; + free(rrset->rri_sigs[i].rdi_data); + } + free(rrset->rri_sigs); } - free(rrset->rri_sigs); - free(rrset->rri_name); + + if (rrset->rri_name) + free(rrset->rri_name); free(rrset); } @@ -280,7 +286,7 @@ parse_dns_response(const char *answer, int size) const char *cp; /* allocate memory for the response */ - resp = malloc(sizeof(*resp)); + resp = calloc(1, sizeof(*resp)); if (resp == NULL) return (NULL); @@ -453,7 +459,8 @@ free_dns_query(struct dns_query *p) if (p == NULL) return; - free(p->name); + if (p->name) + free(p->name); free_dns_query(p->next); free(p); } @@ -464,8 +471,10 @@ free_dns_rr(struct dns_rr *p) if (p == NULL) return; - free(p->name); - free(p->rdata); + if (p->name) + free(p->name); + if (p->rdata) + free(p->rdata); free_dns_rr(p->next); free(p); } |