From c139956e9570bf1e86af61199612600e0ad06bbf Mon Sep 17 00:00:00 2001 From: Walter Doekes <walter+asterisk@wjd.nu> Date: Thu, 2 Jul 2015 13:10:59 +0200 Subject: [PATCH] rtp_engine: Skip useless self-assignment in ast_rtp_engine_unload_format. When running valgrind on Asterisk, it complained about: ==32423== Source and destination overlap in memcpy(0x85a920, 0x85a920, 304) ==32423== at 0x4C2F71C: memcpy@@GLIBC_2.14 (in /usr/lib/valgrind/...) ==32423== by 0x55BA91: ast_rtp_engine_unload_format (rtp_engine.c:2292) ==32423== by 0x4EEFB7: ast_format_attr_unreg_interface (format.c:1437) The code in question is a struct assignment, which may be performed by memcpy as a compiler optimization. It is changed to only copy the struct contents if source and destination are different. ASTERISK-25219 #close Change-Id: I6d3546c326b03378ca8e9b8cefd41c16e0088b9a --- main/rtp_engine.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/main/rtp_engine.c b/main/rtp_engine.c index 13d003d4fb..60b3f55edd 100644 --- a/main/rtp_engine.c +++ b/main/rtp_engine.c @@ -2289,7 +2289,9 @@ int ast_rtp_engine_unload_format(const struct ast_format *format) if (ast_format_cmp(&ast_rtp_mime_types[x].payload_type.format, format) == AST_FORMAT_CMP_EQUAL) { continue; } - ast_rtp_mime_types[y] = ast_rtp_mime_types[x]; + if (x != y) { + ast_rtp_mime_types[y] = ast_rtp_mime_types[x]; + } y++; } mime_types_len = y; -- GitLab