Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
allocation functions set *out to NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jul 12, 2017
1 parent 8c53659 commit 0305c10
Showing 1 changed file with 17 additions and 27 deletions.
44 changes: 17 additions & 27 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,12 @@ htp__path_new_(evhtp_path_t ** out, const char * data, size_t len)
char * path = NULL;
char * file = NULL;

req_path = calloc(sizeof(evhtp_path_t), 1);

req_path = calloc(1, sizeof(*req_path));
evhtp_alloc_assert(req_path);

*out = NULL;

if (evhtp_unlikely(len == 0))
{
/*
Expand All @@ -745,9 +748,9 @@ htp__path_new_(evhtp_path_t ** out, const char * data, size_t len)
* assume the path is "/"
*/
path = strdup("/");
file = strndup(data, len);

evhtp_alloc_assert(path);

file = strndup(data, len);
evhtp_alloc_assert(file);
} else {
if (data[len - 1] != '/')
Expand Down Expand Up @@ -861,16 +864,9 @@ htp__authority_new_(evhtp_authority_t ** out)
{
evhtp_authority_t * authority;

out = NULL;
*out = calloc(1, sizeof(*authority));

if (!(authority = calloc(1, sizeof(*authority))))
{
return -1;
}

*out = authority;

return 0;
return (*out != NULL) ? 0 : -1;
}

/**
Expand Down Expand Up @@ -926,9 +922,10 @@ htp__uri_new_(evhtp_uri_t ** out)
{
evhtp_uri_t * uri;

if (!(uri = calloc(sizeof(evhtp_uri_t), 1)))
*out = NULL;

if ((uri = calloc(1, sizeof(*uri))) == NULL)
{
*out = NULL;
return -1;
}

Expand All @@ -937,11 +934,9 @@ htp__uri_new_(evhtp_uri_t ** out)
if (htp__authority_new_(&uri->authority) == -1)
{
evhtp_safe_free(uri, htp__uri_free_);

return -1;
}


*out = uri;

return 0;
Expand Down Expand Up @@ -3001,15 +2996,11 @@ evhtp_unescape_string(unsigned char ** out, unsigned char * str, size_t str_len)
size_t i;
enum unscape_state state;

if (out == NULL || *out == NULL)
{
return -1;
}

state = unscape_state_start;
optr = *out;
sptr = str;
d = 0;
*out = NULL;

This comment has been minimized.

Copy link
@ripulpatel

ripulpatel Aug 3, 2018

This would break this API as caller is supposed to allocate memory for 'out'. Or we need to assign 'optr' back to '*out' before returning from this function.

Or the intention was to move memory allocation inside this API?

This comment has been minimized.

Copy link
@NathanFrench

NathanFrench Aug 4, 2018

Author Collaborator

Thank you for pointing this out. I gave you credit here: 606f3e3


for (i = 0; i < str_len; i++)
{
Expand Down Expand Up @@ -3074,7 +3065,7 @@ evhtp_unescape_string(unsigned char ** out, unsigned char * str, size_t str_len)
} /* evhtp_unescape_string */

evhtp_query_t *
evhtp_parse_query_wflags(const char * query, size_t len, int flags)
evhtp_parse_query_wflags(const char * query, const size_t len, const int flags)
{
evhtp_query_t * query_args;
query_parser_state state;
Expand Down Expand Up @@ -4841,21 +4832,20 @@ evhtp__new_(evhtp_t ** out, struct event_base * evbase, void * arg)
{
evhtp_t * htp;

if (evhtp_unlikely(out == NULL))
{
return -1;
}

if (evhtp_unlikely(evbase == NULL))
{
return -1;
}

if ((htp = calloc(1, sizeof(evhtp_t))) == NULL)
*out = NULL;

if ((htp = calloc(1, sizeof(*htp))) == NULL)
{
return -1;
}


htp->arg = arg;
htp->evbase = evbase;
htp->flags = EVHTP_FLAG_DEFAULTS;
Expand Down

0 comments on commit 0305c10

Please sign in to comment.