Changeset dc95342 in mainline for uspace/srv/net/dnsres/query.c


Ignore:
Timestamp:
2013-04-22T06:45:49Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
31e9fe0
Parents:
7262f89
Message:

Memory freeing, error paths.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/dnsres/query.c

    r7262f89 rdc95342  
    11/*
    2  * Copyright (c) 2012 Jiri Svoboda
     2 * Copyright (c) 2013 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3636#include <errno.h>
    3737#include <mem.h>
     38#include <stdlib.h>
    3839#include <str.h>
    3940
     
    4748
    4849#include <stdio.h>
    49 int dns_name2host(const char *name, dns_host_info_t *info)
     50int dns_name2host(const char *name, dns_host_info_t **rinfo)
    5051{
    5152        dns_message_t msg;
    5253        dns_message_t *amsg;
    5354        dns_question_t question;
     55        dns_host_info_t *info;
    5456        int rc;
    5557
     
    8183                        rr->name, rr->rtype, rr->rclass, rr->rdata_size);
    8284
    83                 if (rr->rtype == DTYPE_A && rr->rclass == DC_IN) {
    84                         if (rr->rdata_size != sizeof(uint32_t)) {
    85                                 printf("rdata_size = %u - fail\n", rr->rdata_size);
    86                                 return EIO;
     85                if (rr->rtype == DTYPE_A && rr->rclass == DC_IN &&
     86                        rr->rdata_size == sizeof(uint32_t)) {
     87
     88                        info = calloc(1, sizeof(dns_host_info_t));
     89                        if (info == NULL) {
     90                                dns_message_destroy(amsg);
     91                                return ENOMEM;
    8792                        }
    8893
     
    9095                        info->addr.ipv4 = dns_uint32_t_decode(rr->rdata, rr->rdata_size);
    9196                        printf("info->addr = %x\n", info->addr.ipv4);
     97
     98                        dns_message_destroy(amsg);
     99                        *rinfo = info;
    92100                        return EOK;
    93101                }
    94102        }
    95103
     104        dns_message_destroy(amsg);
    96105        printf("no A/IN found, fail\n");
    97106
     
    99108}
    100109
     110void dns_hostinfo_destroy(dns_host_info_t *info)
     111{
     112        free(info->name);
     113        free(info);
     114}
     115
    101116/** @}
    102117 */
Note: See TracChangeset for help on using the changeset viewer.