From: Damir Tomic Date: Thu, 20 Aug 2015 08:15:12 +0000 (+0200) Subject: http-server.c: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b3bb85ff86aa740ec5edd29d6aaffad72737ca1;p=thirdparty%2Fntp.git http-server.c: 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 --- diff --git a/sntp/libevent/sample/http-server.c b/sntp/libevent/sample/http-server.c index e3615cf83..904621d8d 100644 --- a/sntp/libevent/sample/http-server.c +++ b/sntp/libevent/sample/http-server.c @@ -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] = '*'; diff --git a/sntp/libevent/test/bench_httpclient.c b/sntp/libevent/test/bench_httpclient.c index 501484961..1573e365b 100644 --- a/sntp/libevent/test/bench_httpclient.c +++ b/sntp/libevent/test/bench_httpclient.c @@ -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); diff --git a/sntp/libevent/test/regress.c b/sntp/libevent/test/regress.c index 4f1f88859..2d887f02f 100644 --- a/sntp/libevent/test/regress.c +++ b/sntp/libevent/test/regress.c @@ -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, "{[]}", 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; } diff --git a/sntp/libevent/test/regress_dns.c b/sntp/libevent/test/regress_dns.c index e900da004..31811407e 100644 --- a/sntp/libevent/test/regress_dns.c +++ b/sntp/libevent/test/regress_dns.c @@ -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( diff --git a/sntp/libevent/test/regress_http.c b/sntp/libevent/test/regress_http.c index 8cd830519..147f6ff1a 100644 --- a/sntp/libevent/test/regress_http.c +++ b/sntp/libevent/test/regress_http.c @@ -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); diff --git a/sntp/libevent/test/regress_minheap.c b/sntp/libevent/test/regress_minheap.c index 97dee1637..24ff2933b 100644 --- a/sntp/libevent/test/regress_minheap.c +++ b/sntp/libevent/test/regress_minheap.c @@ -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]); } diff --git a/sntp/libevent/test/test-ratelim.c b/sntp/libevent/test/test-ratelim.c index 54afa276c..40a1b9598 100644 --- a/sntp/libevent/test/test-ratelim.c +++ b/sntp/libevent/test/test-ratelim.c @@ -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, diff --git a/sntp/libevent/test/test-time.c b/sntp/libevent/test/test-time.c index 36a7c7b0d..e7dff7d72 100644 --- a/sntp/libevent/test/test-time.c +++ b/sntp/libevent/test/test-time.c @@ -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]);