diff options
author | Christian Grothoff <christian@grothoff.org> | 2018-06-25 20:02:21 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2018-06-25 20:02:21 +0200 |
commit | 2d22da9b531933db65f80ce12b11dd917a387eeb (patch) | |
tree | b4b00e94ce1b577a161d384569600d3aa659687c /src | |
parent | 08c862f4f45eabab77f5b28753c6fe22786db455 (diff) | |
download | gnunet-2d22da9b531933db65f80ce12b11dd917a387eeb.tar.gz gnunet-2d22da9b531933db65f80ce12b11dd917a387eeb.zip |
fix leak
Diffstat (limited to 'src')
-rw-r--r-- | src/dns/gnunet-zonewalk.c | 14 | ||||
-rw-r--r-- | src/util/dnsparser.c | 44 |
2 files changed, 33 insertions, 25 deletions
diff --git a/src/dns/gnunet-zonewalk.c b/src/dns/gnunet-zonewalk.c index c43ad1aeb..b96d40ca7 100644 --- a/src/dns/gnunet-zonewalk.c +++ b/src/dns/gnunet-zonewalk.c | |||
@@ -494,6 +494,7 @@ queue (const char *hostname) | |||
494 | struct Request *req; | 494 | struct Request *req; |
495 | char *raw; | 495 | char *raw; |
496 | size_t raw_size; | 496 | size_t raw_size; |
497 | int ret; | ||
497 | 498 | ||
498 | if (GNUNET_OK != | 499 | if (GNUNET_OK != |
499 | GNUNET_DNSPARSER_check_name (hostname)) | 500 | GNUNET_DNSPARSER_check_name (hostname)) |
@@ -514,13 +515,14 @@ queue (const char *hostname) | |||
514 | p.queries = &q; | 515 | p.queries = &q; |
515 | p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 516 | p.id = (uint16_t) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
516 | UINT16_MAX); | 517 | UINT16_MAX); |
517 | 518 | ret = GNUNET_DNSPARSER_pack (&p, | |
518 | if (GNUNET_OK != | 519 | UINT16_MAX, |
519 | GNUNET_DNSPARSER_pack (&p, | 520 | &raw, |
520 | UINT16_MAX, | 521 | &raw_size); |
521 | &raw, | 522 | if (GNUNET_OK != ret) |
522 | &raw_size)) | ||
523 | { | 523 | { |
524 | if (GNUNET_NO == ret) | ||
525 | GNUNET_free (raw); | ||
524 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 526 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
525 | "Failed to pack query for hostname `%s'\n", | 527 | "Failed to pack query for hostname `%s'\n", |
526 | hostname); | 528 | hostname); |
diff --git a/src/util/dnsparser.c b/src/util/dnsparser.c index 32ad7c0c2..9ed7e4d0e 100644 --- a/src/util/dnsparser.c +++ b/src/util/dnsparser.c | |||
@@ -545,7 +545,9 @@ GNUNET_DNSPARSER_parse_cert (const char *udp_payload, | |||
545 | GNUNET_break_op (0); | 545 | GNUNET_break_op (0); |
546 | return NULL; | 546 | return NULL; |
547 | } | 547 | } |
548 | GNUNET_memcpy (&dcert, &udp_payload[*off], sizeof (struct GNUNET_TUN_DnsCertRecord)); | 548 | GNUNET_memcpy (&dcert, |
549 | &udp_payload[*off], | ||
550 | sizeof (struct GNUNET_TUN_DnsCertRecord)); | ||
549 | (*off) += sizeof (struct GNUNET_TUN_DnsCertRecord); | 551 | (*off) += sizeof (struct GNUNET_TUN_DnsCertRecord); |
550 | cert = GNUNET_new (struct GNUNET_DNSPARSER_CertRecord); | 552 | cert = GNUNET_new (struct GNUNET_DNSPARSER_CertRecord); |
551 | cert->cert_type = ntohs (dcert.cert_type); | 553 | cert->cert_type = ntohs (dcert.cert_type); |
@@ -554,8 +556,8 @@ GNUNET_DNSPARSER_parse_cert (const char *udp_payload, | |||
554 | cert->certificate_size = udp_payload_length - (*off); | 556 | cert->certificate_size = udp_payload_length - (*off); |
555 | cert->certificate_data = GNUNET_malloc (cert->certificate_size); | 557 | cert->certificate_data = GNUNET_malloc (cert->certificate_size); |
556 | GNUNET_memcpy (cert->certificate_data, | 558 | GNUNET_memcpy (cert->certificate_data, |
557 | &udp_payload[*off], | 559 | &udp_payload[*off], |
558 | cert->certificate_size); | 560 | cert->certificate_size); |
559 | (*off) += cert->certificate_size; | 561 | (*off) += cert->certificate_size; |
560 | return cert; | 562 | return cert; |
561 | } | 563 | } |
@@ -684,7 +686,6 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
684 | const struct GNUNET_TUN_DnsHeader *dns; | 686 | const struct GNUNET_TUN_DnsHeader *dns; |
685 | size_t off; | 687 | size_t off; |
686 | unsigned int n; | 688 | unsigned int n; |
687 | unsigned int i; | ||
688 | 689 | ||
689 | if (udp_payload_length < sizeof (struct GNUNET_TUN_DnsHeader)) | 690 | if (udp_payload_length < sizeof (struct GNUNET_TUN_DnsHeader)) |
690 | return NULL; | 691 | return NULL; |
@@ -696,9 +697,10 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
696 | n = ntohs (dns->query_count); | 697 | n = ntohs (dns->query_count); |
697 | if (n > 0) | 698 | if (n > 0) |
698 | { | 699 | { |
699 | p->queries = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Query)); | 700 | p->queries = GNUNET_new_array (n, |
701 | struct GNUNET_DNSPARSER_Query) ; | ||
700 | p->num_queries = n; | 702 | p->num_queries = n; |
701 | for (i=0;i<n;i++) | 703 | for (unsigned int i=0;i<n;i++) |
702 | if (GNUNET_OK != | 704 | if (GNUNET_OK != |
703 | GNUNET_DNSPARSER_parse_query (udp_payload, | 705 | GNUNET_DNSPARSER_parse_query (udp_payload, |
704 | udp_payload_length, | 706 | udp_payload_length, |
@@ -709,9 +711,10 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
709 | n = ntohs (dns->answer_rcount); | 711 | n = ntohs (dns->answer_rcount); |
710 | if (n > 0) | 712 | if (n > 0) |
711 | { | 713 | { |
712 | p->answers = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Record)); | 714 | p->answers = GNUNET_new_array (n, |
715 | struct GNUNET_DNSPARSER_Record); | ||
713 | p->num_answers = n; | 716 | p->num_answers = n; |
714 | for (i=0;i<n;i++) | 717 | for (unsigned int i=0;i<n;i++) |
715 | if (GNUNET_OK != | 718 | if (GNUNET_OK != |
716 | GNUNET_DNSPARSER_parse_record (udp_payload, | 719 | GNUNET_DNSPARSER_parse_record (udp_payload, |
717 | udp_payload_length, | 720 | udp_payload_length, |
@@ -722,9 +725,10 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
722 | n = ntohs (dns->authority_rcount); | 725 | n = ntohs (dns->authority_rcount); |
723 | if (n > 0) | 726 | if (n > 0) |
724 | { | 727 | { |
725 | p->authority_records = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Record)); | 728 | p->authority_records = GNUNET_new_array (n, |
729 | struct GNUNET_DNSPARSER_Record); | ||
726 | p->num_authority_records = n; | 730 | p->num_authority_records = n; |
727 | for (i=0;i<n;i++) | 731 | for (unsigned int i=0;i<n;i++) |
728 | if (GNUNET_OK != | 732 | if (GNUNET_OK != |
729 | GNUNET_DNSPARSER_parse_record (udp_payload, | 733 | GNUNET_DNSPARSER_parse_record (udp_payload, |
730 | udp_payload_length, | 734 | udp_payload_length, |
@@ -735,9 +739,11 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
735 | n = ntohs (dns->additional_rcount); | 739 | n = ntohs (dns->additional_rcount); |
736 | if (n > 0) | 740 | if (n > 0) |
737 | { | 741 | { |
738 | p->additional_records = GNUNET_malloc (n * sizeof (struct GNUNET_DNSPARSER_Record)); | 742 | p->additional_records = GNUNET_new_array (n, |
743 | struct GNUNET_DNSPARSER_Record); | ||
739 | p->num_additional_records = n; | 744 | p->num_additional_records = n; |
740 | for (i=0;i<n;i++) | 745 | for (unsigned int i=0;i<n;i++) |
746 | { | ||
741 | if (GNUNET_OK != | 747 | if (GNUNET_OK != |
742 | GNUNET_DNSPARSER_parse_record (udp_payload, | 748 | GNUNET_DNSPARSER_parse_record (udp_payload, |
743 | udp_payload_length, | 749 | udp_payload_length, |
@@ -761,18 +767,16 @@ GNUNET_DNSPARSER_parse (const char *udp_payload, | |||
761 | void | 767 | void |
762 | GNUNET_DNSPARSER_free_packet (struct GNUNET_DNSPARSER_Packet *p) | 768 | GNUNET_DNSPARSER_free_packet (struct GNUNET_DNSPARSER_Packet *p) |
763 | { | 769 | { |
764 | unsigned int i; | 770 | for (unsigned int i=0;i<p->num_queries;i++) |
765 | |||
766 | for (i=0;i<p->num_queries;i++) | ||
767 | GNUNET_free_non_null (p->queries[i].name); | 771 | GNUNET_free_non_null (p->queries[i].name); |
768 | GNUNET_free_non_null (p->queries); | 772 | GNUNET_free_non_null (p->queries); |
769 | for (i=0;i<p->num_answers;i++) | 773 | for (unsigned int i=0;i<p->num_answers;i++) |
770 | GNUNET_DNSPARSER_free_record (&p->answers[i]); | 774 | GNUNET_DNSPARSER_free_record (&p->answers[i]); |
771 | GNUNET_free_non_null (p->answers); | 775 | GNUNET_free_non_null (p->answers); |
772 | for (i=0;i<p->num_authority_records;i++) | 776 | for (unsigned int i=0;i<p->num_authority_records;i++) |
773 | GNUNET_DNSPARSER_free_record (&p->authority_records[i]); | 777 | GNUNET_DNSPARSER_free_record (&p->authority_records[i]); |
774 | GNUNET_free_non_null (p->authority_records); | 778 | GNUNET_free_non_null (p->authority_records); |
775 | for (i=0;i<p->num_additional_records;i++) | 779 | for (unsigned int i=0;i<p->num_additional_records;i++) |
776 | GNUNET_DNSPARSER_free_record (&p->additional_records[i]); | 780 | GNUNET_DNSPARSER_free_record (&p->additional_records[i]); |
777 | GNUNET_free_non_null (p->additional_records); | 781 | GNUNET_free_non_null (p->additional_records); |
778 | GNUNET_free (p); | 782 | GNUNET_free (p); |
@@ -1148,7 +1152,9 @@ add_record (char *dst, | |||
1148 | rl.dns_traffic_class = htons (record->dns_traffic_class); | 1152 | rl.dns_traffic_class = htons (record->dns_traffic_class); |
1149 | rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value_us / 1000LL / 1000LL); /* in seconds */ | 1153 | rl.ttl = htonl (GNUNET_TIME_absolute_get_remaining (record->expiration_time).rel_value_us / 1000LL / 1000LL); /* in seconds */ |
1150 | rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct GNUNET_TUN_DnsRecordLine)))); | 1154 | rl.data_len = htons ((uint16_t) (pos - (*off + sizeof (struct GNUNET_TUN_DnsRecordLine)))); |
1151 | GNUNET_memcpy (&dst[*off], &rl, sizeof (struct GNUNET_TUN_DnsRecordLine)); | 1155 | GNUNET_memcpy (&dst[*off], |
1156 | &rl, | ||
1157 | sizeof (struct GNUNET_TUN_DnsRecordLine)); | ||
1152 | *off = pos; | 1158 | *off = pos; |
1153 | return GNUNET_OK; | 1159 | return GNUNET_OK; |
1154 | } | 1160 | } |