Changeset a0d97f83 in mainline


Ignore:
Timestamp:
2013-05-03T08:44:14Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ef904895
Parents:
48171fc4
Message:

Fix message allocation/deallocation.

Location:
uspace/srv/net/dnsrsrv
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsrsrv/dns_msg.c

    r48171fc4 ra0d97f83  
    517517        int rc;
    518518
    519         msg = calloc(1, sizeof(dns_message_t));
     519        msg = dns_message_new();
    520520        if (msg == NULL)
    521521                return ENOMEM;
     
    537537            hdr->opbits);
    538538
    539         list_initialize(&msg->question);
    540         list_initialize(&msg->answer);
    541         list_initialize(&msg->authority);
    542         list_initialize(&msg->additional);
    543 
    544539        doff = sizeof(dns_header_t);
    545540
     
    599594}
    600595
     596dns_message_t *dns_message_new(void)
     597{
     598        dns_message_t *msg;
     599
     600        msg = calloc(1, sizeof(dns_message_t));
     601        if (msg == NULL)
     602                return NULL;
     603
     604        list_initialize(&msg->question);
     605        list_initialize(&msg->answer);
     606        list_initialize(&msg->authority);
     607        list_initialize(&msg->additional);
     608
     609        return msg;
     610}
     611
    601612void dns_message_destroy(dns_message_t *msg)
    602613{
  • uspace/srv/net/dnsrsrv/dns_msg.h

    r48171fc4 ra0d97f83  
    4545extern int dns_message_encode(dns_message_t *, void **, size_t *);
    4646extern int dns_message_decode(void *, size_t, dns_message_t **);
     47extern dns_message_t *dns_message_new(void);
    4748extern void dns_message_destroy(dns_message_t *);
    4849extern uint32_t dns_uint32_t_decode(uint8_t *, size_t);
  • uspace/srv/net/dnsrsrv/query.c

    r48171fc4 ra0d97f83  
    5252        dns_message_t *msg;
    5353        dns_message_t *amsg;
    54         dns_question_t question;
     54        dns_question_t *question;
    5555        dns_host_info_t *info;
    5656        int rc;
    5757
    58         question.qname = (char *)name;
    59         question.qtype = DTYPE_A;
    60         question.qclass = DC_IN;
     58        question = calloc(1, sizeof(dns_question_t));
     59        if (question == NULL)
     60                return ENOMEM;
    6161
    62         msg = calloc(1, sizeof(dns_message_t));
     62        question->qname = (char *)name;
     63        question->qtype = DTYPE_A;
     64        question->qclass = DC_IN;
     65
     66        msg = dns_message_new();
    6367        if (msg == NULL)
    6468                return ENOMEM;
    6569
    66         list_initialize(&msg->question);
    67         list_append(&question.msg, &msg->question);
     70        list_append(&question->msg, &msg->question);
    6871
    6972        msg->id = msg_id++;
     
    100103                            info->addr.ipv4);
    101104
     105                        dns_message_destroy(msg);
    102106                        dns_message_destroy(amsg);
    103107                        *rinfo = info;
Note: See TracChangeset for help on using the changeset viewer.