RTP: Fix some memleaks

In the tap, the stream ID allocated on the stack just needs a shallow
copy of the addresses. It only needs a deep copy when being added as a
new entry to the list.

Restore the memleak fix from e76ca2d3cb
that was accidentally removed by 1b4b5e59e9
This commit is contained in:
John Thacker 2023-02-28 18:28:39 -05:00
parent 82da7faee6
commit e51fea444a
3 changed files with 29 additions and 3 deletions

View File

@ -56,6 +56,25 @@ void rtpstream_id_copy_pinfo(const packet_info *pinfo, rtpstream_id_t *dest, gbo
}
}
/****************************************************************************/
/* shallow copy from packet_info to id */
void rtpstream_id_copy_pinfo_shallow(const packet_info *pinfo, rtpstream_id_t *dest, gboolean swap_src_dst)
{
if (!swap_src_dst)
{
copy_address_shallow(&(dest->src_addr), &(pinfo->src));
dest->src_port=pinfo->srcport;
copy_address_shallow(&(dest->dst_addr), &(pinfo->dst));
dest->dst_port=pinfo->destport;
}
else
{
copy_address_shallow(&(dest->src_addr), &(pinfo->dst));
dest->src_port=pinfo->destport;
copy_address_shallow(&(dest->dst_addr), &(pinfo->src));
dest->dst_port=pinfo->srcport;
}
}
/****************************************************************************/
/* free memory allocated for id */
void rtpstream_id_free(rtpstream_id_t *id)

View File

@ -49,10 +49,16 @@ guint rtpstream_id_to_hash(const rtpstream_id_t *id);
void rtpstream_id_copy(const rtpstream_id_t *src, rtpstream_id_t *dest);
/**
* Copy addresses and ports from pinfo
* Deep copy addresses and ports from pinfo
*/
void rtpstream_id_copy_pinfo(const packet_info *pinfo, rtpstream_id_t *dest, gboolean swap_src_dst);
/**
* Shallow copy addresses and ports from pinfo
* Do not call rtpstream_id_free if you use this function.
*/
void rtpstream_id_copy_pinfo_shallow(const packet_info *pinfo, rtpstream_id_t *dest, gboolean swap_src_dst);
/**
* Free memory allocated for id
* it releases address items only, do not release whole structure!

View File

@ -374,8 +374,8 @@ tap_packet_status rtpstream_packet_cb(void *arg, packet_info *pinfo, epan_dissec
rtpdump_info_t rtpdump_info;
/* gather infos on the stream this packet is part of.
* Addresses and strings are read-only and must be duplicated if copied. */
rtpstream_id_copy_pinfo(pinfo,&new_stream_id,FALSE);
* Shallow copy addresses as this is just for examination. */
rtpstream_id_copy_pinfo_shallow(pinfo,&new_stream_id,FALSE);
new_stream_id.ssrc = rtpinfo->info_sync_src;
if (tapinfo->mode == TAP_ANALYSE) {
@ -393,6 +393,7 @@ tap_packet_status rtpstream_packet_cb(void *arg, packet_info *pinfo, epan_dissec
if (!stream_info) {
/* init info and collect id */
stream_info = rtpstream_info_malloc_and_init();
/* Deep copy addresses for the new entry. */
rtpstream_id_copy_pinfo(pinfo,&(stream_info->id),FALSE);
stream_info->id.ssrc = rtpinfo->info_sync_src;