How to rewrite fdb GetKeyValuesReply?

For some reason, I want to rewrite the fdb GetKeyValuesReply before SS send back reply. The code modified in storageserver.actor.cpp:getKeyValuesQ with fdb 7.1.44:

			if (!r.data.empty() && /*some conditions*/) {
				GetKeyValuesReply new_r;
				new_r.arena.dependsOn(r.arena);
				new_r.penalty = r.penalty;
				new_r.more = r.more;
				new_r.version = r.version;
				new_r.cached = r.cached;
				new_r.error = r.error;
				for (int i = 0; i < r.data.size(); i++) {
					if (filterOut(r.data[i].key, r.data[i].value) && (i  != 0 && i != r.data.size() -1)) {
                                        	// filter out the data item except first and last item.
                                        	continue;
					}
					
					new_r.data.push_back(new_r.arena, r.data[i]);
				}
				req.reply.send(new_r);
			} else {
				req.reply.send(r);
			}

when I compile & run above code, it always cause core dump.

Is there something wrong that I didn’t recognize about arena or send func?

I try another way to build my reply, it seems work. example code like:

			if (!r.data.empty() && /*some conditions*/) {
				int offset = 0;
				for (int i = 0; i < r.data.size(); i++) {
					if (filterOut(r.data[i].key, r.data[i].value) && (i  != 0 && i != r.data.size() -1)) {
						continue;
					}
					r.data[offset] = r.data[i];
					offset++;
				}
				while (r.data.size() > offset) { r.data.pop_back(); }
				req.reply.send(r);
			} else {
				req.reply.send(r);
			}

It seems I make some mistakes on arena…

When SS really call send in network level, the new_r memory in above code is freed, then SS access invalid memory address and core dump.

Is anyone can help me explain above problem, or provide some documents about arena?