]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
http-server.c:
authorDamir Tomic <viperus@ntp.org>
Thu, 20 Aug 2015 08:15:12 +0000 (10:15 +0200)
committerDamir Tomic <viperus@ntp.org>
Thu, 20 Aug 2015 08:15:12 +0000 (10:15 +0200)
  reverted emalloc (and similar) to malloc + added checks if malloc is NULL, because emalloc is not linked here.
Many files:
  reverted emalloc (and similar) to malloc + added checks if malloc is NULL, because emalloc is not linked here.

bk: 55d58c90JEJab5Wrv2_PWdzL1J3M8A

sntp/libevent/sample/http-server.c
sntp/libevent/test/bench_httpclient.c
sntp/libevent/test/regress.c
sntp/libevent/test/regress_dns.c
sntp/libevent/test/regress_http.c
sntp/libevent/test/regress_minheap.c
sntp/libevent/test/test-ratelim.c
sntp/libevent/test/test-time.c

index e3615cf8366189e475832a89943f5b4c24eeac22..904621d8df43b6b2be2c9998860b52f6e4dab755 100644 (file)
@@ -200,7 +200,7 @@ send_document_cb(struct evhttp_request *req, void *arg)
                goto err;
 
        len = strlen(decoded_path)+strlen(docroot)+2;
-       if (!(whole_path = emalloc(len))) {
+       if (!(whole_path = malloc(len))) {
                perror("malloc");
                goto err;
        }
@@ -232,7 +232,11 @@ send_document_cb(struct evhttp_request *req, void *arg)
 
 #ifdef _WIN32
                dirlen = strlen(whole_path);
-               pattern = emalloc(dirlen+3);
+               pattern = malloc(dirlen+3);
+               if (!pattern) {
+                       perror("malloc");
+                       goto err;
+               }
                memcpy(pattern, whole_path, dirlen);
                pattern[dirlen] = '\\';
                pattern[dirlen+1] = '*';
index 501484961d62b11a2e23b5b4bb03674f14d4333f..1573e365bfd418ef0d93c0fb483c436008108e32 100644 (file)
@@ -158,7 +158,11 @@ launch_request(void)
                }
        }
 
-       ri = emalloc(sizeof(*ri));
+       ri = malloc(sizeof(*ri));
+       if (ri == NULL) {
+               printf("Unable to allocate memory in launch_request()\n");
+               return -1;
+       }
        ri->n_read = 0;
        evutil_gettimeofday(&ri->started, NULL);
 
index 4f1f888596fc626086cd4cc9a2169ee960ba167c..2d887f02f8eed5f8bd3fd9f3b9e6c49518900727 100644 (file)
@@ -2822,7 +2822,11 @@ check_dummy_mem_ok(void *mem_)
 static void *
 dummy_malloc(size_t len)
 {
-       char *mem = emalloc(len+16);
+       char *mem = malloc(len+16);
+       if (mem == NULL) {
+               fprintf(stderr, "Unable to allocate memory in dummy_malloc()\n");
+               return NULL;
+       }
        memcpy(mem, "{[<guardedram>]}", 16);
        return mem+16;
 }
@@ -2835,7 +2839,7 @@ dummy_realloc(void *mem_, size_t len)
                return dummy_malloc(len);
        tt_want(check_dummy_mem_ok(mem_));
        mem -= 16;
-       mem = erealloc(mem, len+16);
+       mem = realloc(mem, len+16);
        return mem+16;
 }
 
index e900da004ea320e9931c5b2f43446749fddfe9d3..31811407e046a786ffff7da8248b8843e1532e94 100644 (file)
@@ -1322,7 +1322,7 @@ test_getaddrinfo_async(void *arg)
        int n_dns_questions = 0;
        struct evdns_base *dns_base;
 
-       memset(a_out, 0, sizeof(a_out));
+       memset(&a_out, 0, sizeof(a_out));
        memset(&local_outcome, 0, sizeof(local_outcome));
 
        dns_base = evdns_base_new(data->base, 0);
@@ -1746,7 +1746,8 @@ end:
 static void
 gaic_launch(struct event_base *base, struct evdns_base *dns_base)
 {
-       struct gaic_request_status *status = emalloc_zero(1 * sizeof(*status)); //calloc
+       struct gaic_request_status *status = calloc(1, sizeof(*status));
+       tt_assert(status);
        struct timeval tv = { 0, 10000 };
        status->magic = GAIC_MAGIC;
        status->base = base;
@@ -1771,7 +1772,7 @@ static void *
 cnt_malloc(size_t sz)
 {
        allocated_chunks += 1;
-       return emalloc(sz);
+       return malloc(sz);
 }
 
 static void *
@@ -1781,7 +1782,7 @@ cnt_realloc(void *old, size_t sz)
                allocated_chunks += 1;
        if (!sz)
                allocated_chunks -= 1;
-       return erealloc(old, sz);
+       return realloc(old, sz);
 }
 
 static void
@@ -1815,7 +1816,7 @@ testleak_setup(const struct testcase_t *testcase)
        event_enable_debug_mode();
 
        /* not mm_calloc: we don't want to mess with the count. */
-       env = emalloc_zero(1 * sizeof(struct testleak_env_t)); //calloc
+       env = calloc(1, sizeof(struct testleak_env_t));
        env->base = event_base_new();
        env->dns_base = evdns_base_new(env->base, 0);
        env->req = evdns_base_resolve_ipv4(
index 8cd830519787fb4118cacdb1a048f6a123b03065..147f6ff1a76aa0f0049f85d4cead6046fce85d33 100644 (file)
@@ -365,8 +365,12 @@ static void
 http_chunked_cb(struct evhttp_request *req, void *arg)
 {
        struct timeval when = { 0, 0 };
-       struct chunk_req_state *state = emalloc(sizeof(struct chunk_req_state));
+       struct chunk_req_state *state = malloc(sizeof(struct chunk_req_state));
        event_debug(("%s: called\n", __func__));
+       if (state == NULL) {
+               fprintf(stderr, "Unable to allocate memory in http_chunked_cb()\n");
+               exit(1);
+       }
 
        memset(state, 0, sizeof(struct chunk_req_state));
        state->req = req;
@@ -844,7 +848,7 @@ http_allowed_methods_eventcb(struct bufferevent *bev, short what, void *arg)
                        buf[n]='\0';
                        if (*output)
                                free(*output);
-                       *output = estrdup(buf);
+                       *output = strdup(buf);
                }
                event_base_loopexit(exit_base, NULL);
        }
@@ -2643,7 +2647,7 @@ http_uriencode_test(void *ptr)
        s = NULL;
 
        /* Now try decoding just part of string. */
-       s = emalloc(6 + 1 /* NUL byte */);
+       s = malloc(6 + 1 /* NUL byte */);
        bytes_decoded = evhttp_decode_uri_internal("hello%20%20", 6, s, 0);
        tt_assert(s);
        tt_int_op(bytes_decoded,==,6);
index 97dee163731a45204cd7f9629ec5a764b585a31b..24ff2933be2c11e0c1c6ff392e013e6b5bb211dc 100644 (file)
@@ -62,7 +62,8 @@ test_heap_randomized(void *ptr)
        min_heap_ctor_(&heap);
 
        for (i = 0; i < 1024; ++i) {
-               inserted[i] = emalloc(sizeof(struct event));
+               inserted[i] = malloc(sizeof(struct event));
+               assert(inserted[i] != NULL);
                set_random_timeout(inserted[i]);
                min_heap_push_(&heap, inserted[i]);
        }
index 54afa276c381271e020265fad0144d13e5ac494c..40a1b95984ef1f4803ed668b8b5648f886a40b96 100644 (file)
@@ -338,8 +338,12 @@ test_ratelimiting(void)
        if (expected_total_persec > 0)
                expected_total_persec /= seconds_per_tick;
 
-       bevs = emalloc_zero(cfg_n_connections * sizeof(struct bufferevent *)); //calloc
-       states = emalloc_zero(cfg_n_connections * sizeof(struct client_state)); //calloc
+       bevs = calloc(cfg_n_connections, sizeof(struct bufferevent *));
+       states = calloc(cfg_n_connections, sizeof(struct client_state));
+       if (bevs == NULL || states == NULL) {
+               printf("Unable to allocate memory...\n");
+               return 1;
+       }
 
        for (i = 0; i < cfg_n_connections; ++i) {
                bevs[i] = bufferevent_socket_new(base, -1,
index 36a7c7b0ddb2784db2f0b31d5d26decb5922a7d0..e7dff7d7265a7f617f0d4626b12404858184e57b 100644 (file)
@@ -98,7 +98,8 @@ main(int argc, char **argv)
        event_init();
 
        for (i = 0; i < NEVENT; i++) {
-               ev[i] = emalloc(sizeof(struct event));
+               ev[i] = malloc(sizeof(struct event));
+               assert(ev[i] != NULL);
 
                /* Initalize one event */
                evtimer_set(ev[i], time_cb, ev[i]);