Use dynamic memory for DNS table names, saving ~1k RAM.
This commit is contained in:
parent
4a47813e20
commit
125db6595d
|
@ -173,7 +173,7 @@ struct dns_table_entry {
|
||||||
u8_t seqno;
|
u8_t seqno;
|
||||||
u8_t err;
|
u8_t err;
|
||||||
u32_t ttl;
|
u32_t ttl;
|
||||||
char name[DNS_MAX_NAME_LENGTH];
|
char *name;
|
||||||
ip_addr_t ipaddr;
|
ip_addr_t ipaddr;
|
||||||
/* pointer to callback on DNS query done */
|
/* pointer to callback on DNS query done */
|
||||||
dns_found_callback found;
|
dns_found_callback found;
|
||||||
|
@ -673,6 +673,8 @@ dns_check_entry(u8_t i)
|
||||||
if (pEntry->found)
|
if (pEntry->found)
|
||||||
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
|
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
|
||||||
/* flush this entry */
|
/* flush this entry */
|
||||||
|
mem_free (pEntry->name);
|
||||||
|
pEntry->name = NULL;
|
||||||
pEntry->state = DNS_STATE_UNUSED;
|
pEntry->state = DNS_STATE_UNUSED;
|
||||||
pEntry->found = NULL;
|
pEntry->found = NULL;
|
||||||
break;
|
break;
|
||||||
|
@ -697,6 +699,8 @@ dns_check_entry(u8_t i)
|
||||||
if (--pEntry->ttl == 0) {
|
if (--pEntry->ttl == 0) {
|
||||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
|
LWIP_DEBUGF(DNS_DEBUG, ("dns_check_entry: \"%s\": flush\n", pEntry->name));
|
||||||
/* flush this entry */
|
/* flush this entry */
|
||||||
|
mem_free (pEntry->name);
|
||||||
|
pEntry->name = NULL;
|
||||||
pEntry->state = DNS_STATE_UNUSED;
|
pEntry->state = DNS_STATE_UNUSED;
|
||||||
pEntry->found = NULL;
|
pEntry->found = NULL;
|
||||||
}
|
}
|
||||||
|
@ -839,6 +843,8 @@ responseerr:
|
||||||
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
|
(*pEntry->found)(pEntry->name, NULL, pEntry->arg);
|
||||||
}
|
}
|
||||||
/* flush this entry */
|
/* flush this entry */
|
||||||
|
mem_free (pEntry->name);
|
||||||
|
pEntry->name = NULL;
|
||||||
pEntry->state = DNS_STATE_UNUSED;
|
pEntry->state = DNS_STATE_UNUSED;
|
||||||
pEntry->found = NULL;
|
pEntry->found = NULL;
|
||||||
|
|
||||||
|
@ -898,11 +904,16 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg)
|
||||||
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
|
LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": use DNS entry %"U16_F"\n", name, (u16_t)(i)));
|
||||||
|
|
||||||
/* fill the entry */
|
/* fill the entry */
|
||||||
|
namelen = LWIP_MIN(strlen(name), DNS_MAX_NAME_LENGTH-1);
|
||||||
|
char *namebuf = (char *)mem_zalloc (namelen);
|
||||||
|
if (!namebuf)
|
||||||
|
return ERR_MEM;
|
||||||
pEntry->state = DNS_STATE_NEW;
|
pEntry->state = DNS_STATE_NEW;
|
||||||
pEntry->seqno = dns_seqno++;
|
pEntry->seqno = dns_seqno++;
|
||||||
pEntry->found = found;
|
pEntry->found = found;
|
||||||
pEntry->arg = callback_arg;
|
pEntry->arg = callback_arg;
|
||||||
namelen = LWIP_MIN(strlen(name), DNS_MAX_NAME_LENGTH-1);
|
mem_free (pEntry->name);
|
||||||
|
pEntry->name = namebuf;
|
||||||
MEMCPY(pEntry->name, name, namelen);
|
MEMCPY(pEntry->name, name, namelen);
|
||||||
pEntry->name[namelen] = 0;
|
pEntry->name[namelen] = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue