Free args commands when cmds are released
@@ -112,6 +112,14 @@ static void remove_header(h2o_headers_t *headers, h2o_headers_command_t *cmd)
}
+static void dispose_h2o_headers_command(void *_cmds)
+{
+ h2o_headers_command_t *cmds = _cmds;
+ size_t i;
+ for (i = 0; cmds[i].cmd != H2O_HEADERS_CMD_NULL; ++i)
+ free(cmds[i].args);
+}
+
void h2o_headers_append_command(h2o_headers_command_t **cmds, int cmd, struct st_h2o_headers_add_arg_t *args, size_t num_args,
h2o_headers_command_when_t when)
{
@@ -125,13 +133,13 @@ void h2o_headers_append_command(h2o_headers_command_t **cmds, int cmd, struct st
cnt = 0;
}
- new_cmds = h2o_mem_alloc_shared(NULL, (cnt + 2) * sizeof(*new_cmds), NULL);
+ new_cmds = h2o_mem_alloc_shared(NULL, (cnt + 2) * sizeof(*new_cmds), dispose_h2o_headers_command);
if (*cmds != NULL)
memcpy(new_cmds, *cmds, cnt * sizeof(*new_cmds));
new_cmds[cnt] = (h2o_headers_command_t){};
new_cmds[cnt].cmd = cmd;
new_cmds[cnt].when = when;
- new_cmds[cnt].args = h2o_mem_alloc_shared(NULL, sizeof(*new_cmds->args) * num_args, NULL);
+ new_cmds[cnt].args = h2o_mem_alloc(sizeof(*new_cmds->args) * num_args);
for (i = 0; i < num_args; i++) {
new_cmds[cnt].args[i].name = args[i].name;
new_cmds[cnt].args[i].value = args[i].value;
@@ -139,8 +147,11 @@ void h2o_headers_append_command(h2o_headers_command_t **cmds, int cmd, struct st
new_cmds[cnt].num_args = num_args;
new_cmds[cnt + 1] = (h2o_headers_command_t){H2O_HEADERS_CMD_NULL};
- if (*cmds != NULL)
+ if (*cmds != NULL) {
+ for (cnt = 0; (*cmds)[cnt].cmd != H2O_HEADERS_CMD_NULL; ++cnt)
+ (*cmds)[cnt].args = NULL;
h2o_mem_release_shared(*cmds);
+ }
*cmds = new_cmds;
}
