diff --git a/contrib/tsearch2/rank.c b/contrib/tsearch2/rank.c
index 29732c1c91c795226b37c5e0a8828f8a1c93e361..7ffa62051f563dedb7f82f18d3aeefabb4ebfd5b 100644
--- a/contrib/tsearch2/rank.c
+++ b/contrib/tsearch2/rank.c
@@ -748,8 +748,8 @@ rank_cd_def(PG_FUNCTION_ARGS)
 
 	res = calc_rank_cd( weights, txt, query, (PG_NARGS() == 3) ? PG_GETARG_DATUM(2) : DEF_NORM_METHOD);
 	
-	PG_FREE_IF_COPY(txt, 1);
-	PG_FREE_IF_COPY(query, 2);
+	PG_FREE_IF_COPY(txt, 0);
+	PG_FREE_IF_COPY(query, 1);
 
 	PG_RETURN_FLOAT4(res);
 }