call h2o_buffer_try_reserve in the template, free allocated memory upon reallocation failure

This commit is contained in:
Kazuho Oku 2019-06-11 15:30:49 +09:00
parent 083f945642
commit 83d209dcfc
2 changed files with 5 additions and 2 deletions

View File

@ -66,7 +66,7 @@ static h2o_buffer_t *build_dir_listing_html(h2o_mem_pool_t *pool, h2o_iovec_t pa
qsort(files.entries, files.size, sizeof(files.entries[0]), cmpstrptr);
}
h2o_buffer_t *_;
h2o_buffer_t *_ = NULL;
h2o_iovec_t path_normalized_escaped = h2o_htmlescape(pool, path_normalized.base, path_normalized.len);
h2o_buffer_init(&_, &h2o_socket_buffer_prototype);
@ -87,4 +87,7 @@ static h2o_buffer_t *build_dir_listing_html(h2o_mem_pool_t *pool, h2o_iovec_t pa
?</UL>
return _;
NoMemory:
h2o_buffer_dispose(&_);
return NULL;
}

View File

@ -3,7 +3,7 @@ use warnings;
$main::push_expr = sub {
my $src = shift;
return qq{{ h2o_iovec_t _s = ($src); if (_s.len != 0 && _s.base[_s.len - 1] == '\\n') --_s.len; h2o_buffer_reserve(&_, _s.len); memcpy(_->bytes + _->size, _s.base, _s.len); _->size += _s.len; }};
return qq{{ h2o_iovec_t _s = ($src); if (_s.len != 0 && _s.base[_s.len - 1] == '\\n') --_s.len; if (h2o_buffer_try_reserve(&_, _s.len).base == NULL) goto NoMemory; memcpy(_->bytes + _->size, _s.base, _s.len); _->size += _s.len; }};
};
$main::push_void_expr = sub {