Hi! I'm trying to follow Julias advise in https://www.mail-archive.com/cocci@systeme.lip6.fr/msg06465.html ---8<--- > > Unfortunately, I stumble on the error message “replacement: already > > tagged token: > > C code context” then. This is what I would expect. You could use one rule with an exists to put a position variable in the place where you want to put a kfree, and then use another rule to put a kfree at that position. ---8<--- I'm attaching my sample inp.c and my attempt at the script and would be glad if you could give some guidance how to properly phrase the replacement rule. In effect, i want to insert *multiple* hunks, each hunk before the respective single return statement. TIA for your help or any pointers and cheers, PS: In case it matters, i'm using the debian package which is spatch version 1.1.1 compiled with OCaml version 4.13.1 The two attached scripts are identical, just sed -i -e s/mpz/mpfr/g If i patch the mpfr part of inp.c, then all works like i would envision, since there is just a single replacement to be done: $ spatch --sp-file ~/mpfr_free.0.cocci /tmp/inp.cc;echo EOF init_defs_builtins: /usr/lib/coccinelle/standard.h HANDLING: /tmp/inp.cc diff = --- /tmp/inp.cc +++ /tmp/cocci-output-1395250-146bec-inp.cc @@ -34,9 +34,11 @@ CompileExpr::compile_float_literal (cons rust_error_at (expr.get_locus (), "decimal overflows the respective type %<%s%>", tyty->get_name ().c_str ()); + mpfr_clear(fval); return error_mark_node; } + mpfr_clear(fval); return real_value; } EOF But when attempting to insert multiple "free()" for a handful of identifiers in the mpz case, then: $ spatch --sp-file ~/mpz_free.0.cocci /tmp/inp.cc ; echo EOF init_defs_builtins: /usr/lib/coccinelle/standard.h HANDLING: /tmp/inp.cc previous modification: <<< mpz_clear(i); CONTEXT According to environment 4: mpz_0_find.i -> id ival mpz_0_find.ret_pos -> poss[(/tmp/inp.cc,CompileExpr::compile_integer_literal,((44,0),(80,1)),(71,6),(71,12))] mpz_0_find.i -> id ival mpz_0_find.ret_pos -> poss[(/tmp/inp.cc,CompileExpr::compile_integer_literal,((44,0),(80,1)),(71,6),(71,12))] current modification: <<< mpz_clear(i); CONTEXT According to environment 4: mpz_0_find.i -> id type_max mpz_0_find.ret_pos -> poss[(/tmp/inp.cc,CompileExpr::compile_integer_literal,((44,0),(80,1)),(71,6),(71,12))] mpz_0_find.i -> id type_max mpz_0_find.ret_pos -> poss[(/tmp/inp.cc,CompileExpr::compile_integer_literal,((44,0),(80,1)),(71,6),(71,12))] mpz_0_replace: already tagged token: C code context File "/tmp/inp.cc", line 71, column 6, charpos = 1993 around = 'return', whole content = return error_mark_node; EOF Isn't this OK nevertheless?