Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/ntp/dist/libntp pointless to call alloca for a ...



details:   https://anonhg.NetBSD.org/src/rev/900dda2c934c
branches:  trunk
changeset: 325614:900dda2c934c
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Dec 31 20:56:29 2013 +0000

description:
pointless to call alloca for a 1K path string... Just allocate it on the stack!

diffstat:

 external/bsd/ntp/dist/libntp/ntp_intres.c |  20 +++-----------------
 1 files changed, 3 insertions(+), 17 deletions(-)

diffs (48 lines):

diff -r dd84701b7c9c -r 900dda2c934c external/bsd/ntp/dist/libntp/ntp_intres.c
--- a/external/bsd/ntp/dist/libntp/ntp_intres.c Tue Dec 31 20:27:57 2013 +0000
+++ b/external/bsd/ntp/dist/libntp/ntp_intres.c Tue Dec 31 20:56:29 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ntp_intres.c,v 1.1.1.1 2013/12/27 23:30:47 christos Exp $      */
+/*     $NetBSD: ntp_intres.c,v 1.2 2013/12/31 20:56:29 christos Exp $  */
 
 /*
  * ntp_intres.c - Implements a generic blocking worker child or thread,
@@ -691,6 +691,7 @@
        char *                  cp;
        int                     rc;
        time_t                  time_now;
+       char                    host[1024];
 
        gni_req = (void *)((char *)req + sizeof(*req));
 
@@ -701,19 +702,7 @@
         * large allocations.  We only need room for the host
         * and service names.
         */
-       NTP_REQUIRE(octets < 1024);
-
-#ifndef HAVE_ALLOCA
-       host = emalloc(octets);
-#else
-       host = alloca(octets);
-       if (NULL == host) {
-               msyslog(LOG_ERR,
-                       "blocking_getnameinfo unable to allocate %lu octets on stack",
-                       (u_long)octets);
-               exit(1);
-       }
-#endif
+       NTP_REQUIRE(octets < sizeof(host));
        service = host + gni_req->hostoctets;
 
        worker_ctx = get_worker_context(c, gni_req->dns_idx);
@@ -795,9 +784,6 @@
        rc = queue_blocking_response(c, resp, resp_octets, req);
        if (rc)
                msyslog(LOG_ERR, "blocking_getnameinfo unable to queue response");
-#ifndef HAVE_ALLOCA
-       free(host);
-#endif
        return rc;
 }
 



Home | Main Index | Thread Index | Old Index