src: use internal_location for unspecified location at allocation time
Pablo Neira Ayuso
maintainerPATCH 1/2 src: use internal_location for unspecified location at allocation time
Set location to internal_location instead of NULL to ensure this is always set.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/parser_bison.y | 8 ++++---- src/rule.c | 21 ++++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-)
src/parser_bison.y +4 -4
@@ -2134,7 +2134,7 @@ typeof_expr : primary_expr set_block_alloc : /* empty */ { - $$ = set_alloc(NULL); + $$ = set_alloc(&internal_location); } ;
@@ -2214,7 +2214,7 @@ set_flag : CONSTANT { $$ = NFT_SET_CONSTANT; } map_block_alloc : /* empty */ { - $$ = set_alloc(NULL); + $$ = set_alloc(&internal_location); } ;
@@ -2329,7 +2329,7 @@ set_policy_spec : PERFORMANCE { $$ = NFT_SET_POL_PERFORMANCE; } flowtable_block_alloc : /* empty */ { - $$ = flowtable_alloc(NULL); + $$ = flowtable_alloc(&internal_location); } ;
@@ -2448,7 +2448,7 @@ data_type_expr : data_type_atom_expr obj_block_alloc : /* empty */ { - $$ = obj_alloc(NULL); + $$ = obj_alloc(&internal_location); } ;
src/rule.c +14 -7
@@ -148,11 +148,12 @@ struct set *set_alloc(const struct location *loc) {struct set *set; +assert (loc); + set =xzalloc (sizeof (*set)); set->refcnt =1 ; set->handle.set_id = ++set_id; -if (loc !=NULL ) - set->location = *loc; + set->location = *loc;init_list_head (&set->stmt_list);
@@ -163,7 +164,7 @@ struct set *set_clone(const struct set *set) {struct set *new_set; - new_set =set_alloc (NULL ); + new_set =set_alloc (&internal_location);handle_merge (&new_set->handle, &set->handle); new_set->flags = set->flags; new_set->gc_int = set->gc_int;
@@ -455,6 +456,8 @@ struct rule *rule_alloc(const struct location *loc, const struct handle *h) {struct rule *rule; +assert (loc); + rule =xzalloc (sizeof (*rule)); rule->location = *loc;init_list_head (&rule->list);
@@ -1300,6 +1303,8 @@ struct cmd *cmd_alloc(enum cmd_ops op, enum cmd_obj obj, {struct cmd *cmd; +assert (loc); + cmd =xzalloc (sizeof (*cmd));init_list_head (&cmd->list); cmd->op = op;
@@ -1614,9 +1619,10 @@ struct obj *obj_alloc(const struct location *loc) {struct obj *obj; +assert (loc); + obj =xzalloc (sizeof (*obj)); -if (loc !=NULL ) - obj->location = *loc; + obj->location = *loc; obj->refcnt =1 ;return obj;
@@ -2025,9 +2031,10 @@ struct flowtable *flowtable_alloc(const struct location *loc) {struct flowtable *flowtable; +assert (loc); + flowtable =xzalloc (sizeof (*flowtable)); -if (loc !=NULL ) - flowtable->location = *loc; + flowtable->location = *loc; flowtable->refcnt =1 ;return flowtable;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/2 src: remove check for NULL before calling expr_free()
expr_free() already handles NULL pointer, remove redundant check.
Signed-off-by Pablo Neira Ayuso <[email protected]>
--- src/netlink_delinearize.c | 3 +-- src/rule.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-)
src/netlink_delinearize.c +1 -2
@@ -83,8 +83,7 @@ static void netlink_set_register(struct netlink_parse_ctx *ctx,return ; } -if (ctx->registers[reg] !=NULL ) -expr_free (ctx->registers[reg]); +expr_free (ctx->registers[reg]); ctx->registers[reg] = expr; }
src/rule.c +2 -2
@@ -193,8 +193,8 @@ void set_free(struct set *set)if (--set->refcnt >0 )return ; -if (set->init !=NULL ) -expr_free (set->init); + +expr_free (set->init);if (set->comment)xfree (set->comment);handle_free (&set->handle);
Signature · 1 line
2.30.2