summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSami Kerola <kerolasa@iki.fi>2018-01-15 22:53:54 +0000
committerSami Kerola <kerolasa@iki.fi>2018-10-03 20:28:46 +0100
commit562c8199131aeee7b095acaa5af4962ea913fd99 (patch)
tree6e84e4c6ed1ea46ed6f5d848641322d73777cf77
parentd4c8e7c405d535ce25336c73e919cba14d968557 (diff)
downloadiputils-562c8199131aeee7b095acaa5af4962ea913fd99.tar.gz
ninfod: remove syslog based malloc debugging
There are better ways to debug allocations, for example valgrind and address & leak sanitizers. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r--ninfod/ninfod.c10
-rw-r--r--ninfod/ninfod.h14
-rw-r--r--ninfod/ninfod_addrs.c4
-rw-r--r--ninfod/ninfod_core.c38
-rw-r--r--ninfod/ninfod_name.c2
5 files changed, 27 insertions, 41 deletions
diff --git a/ninfod/ninfod.c b/ninfod/ninfod.c
index 44843f6..c982d1c 100644
--- a/ninfod/ninfod.c
+++ b/ninfod/ninfod.c
@@ -341,8 +341,8 @@ int ni_send(struct packetcontext *p)
if (cc < 0)
DEBUG(LOG_DEBUG, "sendmsg(): %s\n", strerror(errno));
- ni_free(p->replydata);
- ni_free(p);
+ free(p->replydata);
+ free(p);
return cc;
}
@@ -676,7 +676,7 @@ int main (int argc, char **argv)
init_core(0);
- p = ni_malloc(sizeof(*p));
+ p = malloc(sizeof(*p));
if (!p) {
DEBUG(LOG_WARNING, "%s(): failed to allocate packet context; sleep 1 sec.\n",
__func__);
@@ -711,7 +711,7 @@ int main (int argc, char **argv)
init_core(0);
if (p->querylen < sizeof(struct icmp6_hdr)) {
- ni_free(p);
+ free(p);
#if ENABLE_DEBUG
DEBUG(LOG_WARNING, "Too short icmp message from %s\n", saddrbuf);
#endif
@@ -731,7 +731,7 @@ int main (int argc, char **argv)
"Strange icmp type %d from %s\n",
icmph->icmp6_type, saddrbuf);
#endif
- ni_free(p);
+ free(p);
continue;
}
diff --git a/ninfod/ninfod.h b/ninfod/ninfod.h
index 513e2e2..8468661 100644
--- a/ninfod/ninfod.h
+++ b/ninfod/ninfod.h
@@ -108,20 +108,6 @@ int ni_send(struct packetcontext *p);
/* ninfod_core.c */
extern void DEBUG(int pri, char *fmt, ...);
-#define ni_malloc(size) ({ \
- size_t _size = (size); \
- void *ptr = malloc(_size); \
- DEBUG(LOG_DEBUG, "%s(): malloc(%zu) = %p\n", __func__, _size, ptr); \
- ptr; \
- })
-#define ni_free(p) ({ \
- void *_p = (p); \
- int saved_errno = errno; \
- DEBUG(LOG_DEBUG, "%s(): free(%p)\n", __func__, _p); \
- free(_p); \
- errno = saved_errno; \
- })
-
void init_core(int forced);
int pr_nodeinfo(struct packetcontext *p);
diff --git a/ninfod/ninfod_addrs.c b/ninfod/ninfod_addrs.c
index a9c7129..5a62161 100644
--- a/ninfod/ninfod_addrs.c
+++ b/ninfod/ninfod_addrs.c
@@ -242,7 +242,7 @@ int pr_nodeinfo_ipv6addr(CHECKANDFILL_ARGS)
/* pass 2: store addresses */
p->replydatalen = (sizeof(uint32_t)+sizeof(struct in6_addr)) * addrs0;
- p->replydata = p->replydatalen ? ni_malloc(p->replydatalen) : NULL;
+ p->replydata = p->replydatalen ? malloc(p->replydatalen) : NULL;
if (p->replydatalen && !p->replydata) {
p->reply.ni_flags |= NI_NODEADDR_FLAG_TRUNCATE;
@@ -395,7 +395,7 @@ int pr_nodeinfo_ipv4addr(CHECKANDFILL_ARGS)
/* pass 2: store addresses */
p->replydatalen = (sizeof(uint32_t)+sizeof(struct in_addr)) * addrs0;
- p->replydata = addrs0 ? ni_malloc(p->replydatalen) : NULL;
+ p->replydata = addrs0 ? malloc(p->replydatalen) : NULL;
if (p->replydatalen && !p->replydata) {
p->reply.ni_flags |= NI_NODEADDR_FLAG_TRUNCATE;
diff --git a/ninfod/ninfod_core.c b/ninfod/ninfod_core.c
index e6af2da..6aa36a5 100644
--- a/ninfod/ninfod_core.c
+++ b/ninfod/ninfod_core.c
@@ -270,7 +270,7 @@ int pr_nodeinfo_suptypes(CHECKANDFILL_ARGS)
p->reply.ni_flags = flags&~NI_SUPTYPE_FLAG_COMPRESS;
p->replydatalen = suptypes_len<<2;
- p->replydata = ni_malloc(p->replydatalen);
+ p->replydata = malloc(p->replydatalen);
if (p->replydata == NULL) {
p->replydatalen = -1;
return -1; /*XXX*/
@@ -454,13 +454,13 @@ static int ni_send_fork(struct packetcontext *p)
__func__, getpid(), ret);
exit(ret > 0 ? 1 : 0);
}
- ni_free(p->replydata);
- ni_free(p);
+ free(p->replydata);
+ free(p);
exit(0);
} else {
waitpid(child, NULL, 0);
- ni_free(p->replydata);
- ni_free(p);
+ free(p->replydata);
+ free(p);
}
return 0;
}
@@ -519,7 +519,7 @@ int pr_nodeinfo(struct packetcontext *p)
if (!IN6_IS_ADDR_MC_LINKLOCAL(&p->pktinfo.ipi6_addr)) {
DEBUG(LOG_WARNING,
"Destination is non-link-local multicast address.\n");
- ni_free(p);
+ free(p);
return -1;
}
#if 0
@@ -530,7 +530,7 @@ int pr_nodeinfo(struct packetcontext *p)
DEBUG(LOG_WARNING,
"Destination is link-local multicast address other than "
"NI Group address.\n");
- ni_free(p);
+ free(p);
return -1;
}
#endif
@@ -539,7 +539,7 @@ int pr_nodeinfo(struct packetcontext *p)
/* Step 1: Check length */
if (p->querylen < sizeof(struct icmp6_nodeinfo)) {
DEBUG(LOG_WARNING, "Query too short\n");
- ni_free(p);
+ free(p);
return -1;
}
@@ -573,7 +573,7 @@ int pr_nodeinfo(struct packetcontext *p)
DEBUG(LOG_WARNING,
"%s(): unknown code %u\n",
__func__, query->ni_code);
- ni_free(p);
+ free(p);
return -1;
}
}
@@ -597,19 +597,19 @@ int pr_nodeinfo(struct packetcontext *p)
"failed to make reply: %s\n",
strerror(errno));
}
- ni_free(p);
+ free(p);
return -1;
}
/* XXX: Step 5: Check the policy */
rc = ni_policy(p);
if (rc <= 0) {
- ni_free(p->replydata);
+ free(p->replydata);
p->replydata = NULL;
p->replydatalen = 0;
if (rc < 0) {
DEBUG(LOG_WARNING, "Ignored by policy.\n");
- ni_free(p);
+ free(p);
return -1;
}
DEBUG(LOG_WARNING, "Refused by policy.\n");
@@ -629,7 +629,7 @@ int pr_nodeinfo(struct packetcontext *p)
"failed to make reply: %s\n",
strerror(errno));
}
- ni_free(p);
+ free(p);
return -1;
}
}
@@ -637,8 +637,8 @@ int pr_nodeinfo(struct packetcontext *p)
/* Step 7: Rate Limit */
if (qtypeinfo->flags&QTYPEINFO_F_RATELIMIT &&
ni_ratelimit()) {
- ni_free(p->replydata);
- ni_free(p);
+ free(p->replydata);
+ free(p);
return -1;
}
@@ -667,15 +667,15 @@ int pr_nodeinfo(struct packetcontext *p)
#if ENABLE_THREADS && HAVE_LIBPTHREAD
/* ni_send_thread() frees p */
if (pthread_create(&thread, &pattr, ni_send_thread, p)) {
- ni_free(p->replydata);
- ni_free(p);
+ free(p->replydata);
+ free(p);
return -1;
}
#else
/* ni_send_fork() frees p */
if (ni_send_fork(p)) {
- ni_free(p->replydata);
- ni_free(p);
+ free(p->replydata);
+ free(p);
return -1;
}
#endif
diff --git a/ninfod/ninfod_name.c b/ninfod/ninfod_name.c
index 41fe0ad..8694bd4 100644
--- a/ninfod/ninfod_name.c
+++ b/ninfod/ninfod_name.c
@@ -363,7 +363,7 @@ int pr_nodeinfo_nodename(CHECKANDFILL_ARGS_2)
p->reply.ni_flags = 0;
p->replydatalen = nodenamelen ? sizeof(ttl)+nodenamelen : 0;
- p->replydata = nodenamelen ? ni_malloc(p->replydatalen) : NULL;
+ p->replydata = nodenamelen ? malloc(p->replydatalen) : NULL;
if (p->replydata) {
memcpy(p->replydata, &ttl, sizeof(ttl));
memcpy(p->replydata + sizeof(ttl), &nodename, nodenamelen);