Fixing bug 2898, replacing malloc with emalloc, calloc with emalloc_zero, strdup with estrup etc.
Many files:
Fixing bug 2898, replacing malloc with emalloc, calloc with emalloc_zero, strdup with estrup etc.
bk: 55d501eeU564GNQIc_l35Hx9MHdIDg
{
struct hostent *host1;
h_errno = 0; /* we are always successful!!! */
- host1 = (struct hostent *) malloc (sizeof(struct hostent));
+ host1 = (struct hostent *) emalloc (sizeof(struct hostent));
host1->h_name = name;
host1->h_addrtype = AF_INET;
host1->h_aliases = name;
{
struct hostent *host1;
h_errno = 0; /* we are always successful!!! */
- host1 = (struct hostent *) malloc (sizeof(struct hostent));
+ host1 = (struct hostent *) emalloc (sizeof(struct hostent));
host1->h_name = name;
host1->h_addrtype = AF_INET;
host1->h_aliases = name;
struct servent *getservbyname (char *name, char *type)
{
struct servent *serv1;
- serv1 = (struct servent *) malloc (sizeof(struct servent));
+ serv1 = (struct servent *) emalloc (sizeof(struct servent));
serv1->s_name = "ntp"; /* official service name */
serv1->s_aliases = NULL; /* alias list */
serv1->s_port = 123; /* port # */
struct packettx tx;
tx.size = 0;
- tx.data = (u_char *) malloc(100);
+ tx.data = (u_char *) emalloc(100);
/* set UTC time */
sendsupercmd (&tx, 0x8E, 0xA2);
struct packettx tx;
tx.size = 0;
- tx.data = (u_char *) malloc(100);
+ tx.data = (u_char *) emalloc(100);
sendsupercmd(&tx, 0x8E, 0xA5);
sendbyte(&tx, 0x02);
builtins[icmd].desc[0] = "md5";
fmt = "set key type to use for authenticated requests (%s)";
#endif
- msg = malloc(strlen(fmt) + strlen(list) - strlen("%s") +1);
+ msg = emalloc(strlen(fmt) + strlen(list) - strlen("%s") +1);
sprintf(msg, fmt, list);
builtins[icmd].comment = msg;
free(list);
if (!strcmp(*seen, name))
return;
n = (seen - hstate->seen) + 2;
- hstate->seen = realloc(hstate->seen, n * sizeof(*seen));
+ hstate->seen = erealloc(hstate->seen, n * sizeof(*seen));
hstate->seen[n-2] = name;
hstate->seen[n-1] = NULL;
len += (hstate->idx >= K_PER_LINE)? strlen(K_NL_PFX_STR): strlen(K_DELIM_STR);
if (hstate->list == NULL) {
- hstate->list = (char *)malloc(len);
+ hstate->list = (char *)emalloc(len);
hstate->list[0] = '\0';
} else
- hstate->list = (char *)realloc(hstate->list, len);
+ hstate->list = (char *)erealloc(hstate->list, len);
sprintf(hstate->list + strlen(hstate->list), "%s%s",
((hstate->idx >= K_PER_LINE)? K_NL_PFX_STR : K_DELIM_STR),
# ifdef HAVE_EVP_MD_DO_ALL_SORTED
struct hstate hstate = { NULL, NULL, K_PER_LINE+1 };
- hstate.seen = (const char **)calloc(1, sizeof( const char * ));
+ hstate.seen = (const char **) emalloc_zero(1*sizeof( const char * )); // replaces -> calloc(1, sizeof( const char * ));
INIT_SSL();
EVP_MD_do_all_sorted(list_md_fn, &hstate);
list = hstate.list;
free(hstate.seen);
# else
- list = (char *)malloc(sizeof("md5, others (upgrade to OpenSSL-1.0 for full list)"));
+ list = (char *)emalloc(sizeof("md5, others (upgrade to OpenSSL-1.0 for full list)"));
strcpy(list, "md5, others (upgrade to OpenSSL-1.0 for full list)");
# endif
#else
- list = (char *)malloc(sizeof("md5"));
+ list = (char *)emalloc(sizeof("md5"));
strcpy(list, "md5");
#endif
goto err;
len = strlen(decoded_path)+strlen(docroot)+2;
- if (!(whole_path = malloc(len))) {
+ if (!(whole_path = emalloc(len))) {
perror("malloc");
goto err;
}
#ifdef _WIN32
dirlen = strlen(whole_path);
- pattern = malloc(dirlen+3);
+ pattern = emalloc(dirlen+3);
memcpy(pattern, whole_path, dirlen);
pattern[dirlen] = '\\';
pattern[dirlen+1] = '*';
}
}
- ri = malloc(sizeof(*ri));
+ ri = emalloc(sizeof(*ri));
ri->n_read = 0;
evutil_gettimeofday(&ri->started, NULL);
static void *
dummy_malloc(size_t len)
{
- char *mem = malloc(len+16);
+ char *mem = emalloc(len+16);
memcpy(mem, "{[<guardedram>]}", 16);
return mem+16;
}
return dummy_malloc(len);
tt_want(check_dummy_mem_ok(mem_));
mem -= 16;
- mem = realloc(mem, len+16);
+ mem = erealloc(mem, len+16);
return mem+16;
}
static void
gaic_launch(struct event_base *base, struct evdns_base *dns_base)
{
- struct gaic_request_status *status = calloc(1,sizeof(*status));
+ struct gaic_request_status *status = emalloc_zero(1 * sizeof(*status)); //calloc
struct timeval tv = { 0, 10000 };
status->magic = GAIC_MAGIC;
status->base = base;
cnt_malloc(size_t sz)
{
allocated_chunks += 1;
- return malloc(sz);
+ return emalloc(sz);
}
static void *
allocated_chunks += 1;
if (!sz)
allocated_chunks -= 1;
- return realloc(old, sz);
+ return erealloc(old, sz);
}
static void
event_enable_debug_mode();
/* not mm_calloc: we don't want to mess with the count. */
- env = calloc(1, sizeof(struct testleak_env_t));
+ env = emalloc_zero(1 * sizeof(struct testleak_env_t)); //calloc
env->base = event_base_new();
env->dns_base = evdns_base_new(env->base, 0);
env->req = evdns_base_resolve_ipv4(
http_chunked_cb(struct evhttp_request *req, void *arg)
{
struct timeval when = { 0, 0 };
- struct chunk_req_state *state = malloc(sizeof(struct chunk_req_state));
+ struct chunk_req_state *state = emalloc(sizeof(struct chunk_req_state));
event_debug(("%s: called\n", __func__));
memset(state, 0, sizeof(struct chunk_req_state));
buf[n]='\0';
if (*output)
free(*output);
- *output = strdup(buf);
+ *output = estrdup(buf);
}
event_base_loopexit(exit_base, NULL);
}
s = NULL;
/* Now try decoding just part of string. */
- s = malloc(6 + 1 /* NUL byte */);
+ s = emalloc(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);
min_heap_ctor_(&heap);
for (i = 0; i < 1024; ++i) {
- inserted[i] = malloc(sizeof(struct event));
+ inserted[i] = emalloc(sizeof(struct event));
set_random_timeout(inserted[i]);
min_heap_push_(&heap, inserted[i]);
}
if (expected_total_persec > 0)
expected_total_persec /= seconds_per_tick;
- bevs = calloc(cfg_n_connections, sizeof(struct bufferevent *));
- states = calloc(cfg_n_connections, sizeof(struct client_state));
+ bevs = emalloc_zero(cfg_n_connections * sizeof(struct bufferevent *)); //calloc
+ states = emalloc_zero(cfg_n_connections * sizeof(struct client_state)); //calloc
for (i = 0; i < cfg_n_connections; ++i) {
bevs[i] = bufferevent_socket_new(base, -1,
event_init();
for (i = 0; i < NEVENT; i++) {
- ev[i] = malloc(sizeof(struct event));
+ ev[i] = emalloc(sizeof(struct event));
/* Initalize one event */
evtimer_set(ev[i], time_cb, ev[i]);
char const * fname,
char const * mode )
{
- return strdup(fname);
+ return estrdup(fname);
}
#else
int result_len;
if (!dot_path || *string == '/') {
- result = strdup( string );
+ result = estrdup( string );
} else {
if (dot_path && dot_path[0]) {
- result = malloc( 2 + strlen( dot_path ) + strlen( string ) );
+ result = emalloc( 2 + strlen( dot_path ) + strlen( string ) );
strcpy( result, dot_path );
result_len = (int)strlen(result);
if (result[result_len - 1] != '/') {
result[result_len] = '\0';
}
} else {
- result = malloc( 3 + strlen( string ) );
+ result = emalloc( 3 + strlen( string ) );
result[0] = '.'; result[1] = '/'; result[2] = '\0';
result_len = 2;
}
char stub_char, *result;
/* The result cannot be larger than the input PATH. */
- result = strdup( path );
+ result = estrdup( path );
stub_char = (*path == '/') ? '/' : '.';
const char *
CreatePath(const char* filename, enum DirectoryType argument) {
const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/";
- char * path = malloc (sizeof (char) * (strlen(srcdir) + 256));
+ char * path = emalloc (sizeof (char) * (strlen(srcdir) + 256));
//char cwd[1024];
ActivateOption("-a", str);
key_cnt = 1;
- key_ptr = malloc(sizeof(struct key));
+ key_ptr = emalloc(sizeof(struct key));
key_ptr->next = NULL;
key_ptr->key_id = key_id;
key_ptr->key_len = key_len;
char *packetPtr;
int length;
- packetPtr = malloc(totalLength * sizeof(*packetPtr));
+ packetPtr = emalloc(totalLength * sizeof(*packetPtr));
memset(packetPtr + packetLength, 0, keyIdLength);
memcpy(packetPtr, packet, packetLength);
char *
CalendarFromCalToString(const struct calendar cal) {
- char * str = malloc (sizeof (char) * 100);
+ char * str = emalloc (sizeof (char) * 100);
char buffer[100] ="";
snprintf(buffer, 100, "%u", cal.year);
char *
CalendarFromIsoToString(const struct isodate iso) {
- char * str = malloc (sizeof (char) * 100);
+ char * str = emalloc (sizeof (char) * 100);
char buffer[100] ="";
snprintf(buffer, 100, "%u", iso.year);
char *
DateFromCalToString(const struct calendar cal) {
- char * str = malloc (sizeof (char) * 100);
+ char * str = emalloc (sizeof (char) * 100);
char buffer[100] ="";
snprintf(buffer, 100, "%u", cal.year);
char *
DateFromIsoToString(const struct isodate iso) {
- char * str = malloc (sizeof (char) * 100);
+ char * str = emalloc (sizeof (char) * 100);
char buffer[100] ="";
snprintf(buffer, 100, "%u", iso.year);
char *
CalendarToString(const struct calendar cal) {
- char * str = malloc (sizeof (char) * 100);
+ char * str = emalloc (sizeof (char) * 100);
char buffer[100] ="";
snprintf(buffer, 100, "%u", cal.year);