Changeset 7d1ada1


Ignore:
Timestamp:
02/23/16 16:03:43 (5 years ago)
Author:
Perry Lorier <git@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
a1935fa
Parents:
9636216
Message:

Fix memory management of trace_construct_packet.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/trace.c

    r9636216 r7d1ada1  
    17811781
    17821782        /* Now fill in the libtrace packet itself */
     1783        assert(deadtrace);
    17831784        packet->trace=deadtrace;
    17841785        size=len+sizeof(hdr);
     1786        if (size < LIBTRACE_PACKET_BUFSIZE)
     1787            size = LIBTRACE_PACKET_BUFSIZE;
    17851788        if (packet->buf_control==TRACE_CTRL_PACKET) {
    1786                 packet->buffer=realloc(packet->buffer,size);
     1789            packet->buffer = realloc(packet->buffer, size);
    17871790        }
    17881791        else {
    1789                 packet->buffer=malloc(size);
     1792                packet->buffer = malloc(size);
    17901793        }
    17911794        packet->buf_control=TRACE_CTRL_PACKET;
    17921795        packet->header=packet->buffer;
    17931796        packet->payload=(void*)((char*)packet->buffer+sizeof(hdr));
    1794        
    1795         /* Ugh, memcpy - sadly necessary */
    1796         memcpy(packet->header,&hdr,sizeof(hdr));
    1797         memcpy(packet->payload,data,(size_t)len);
     1797
     1798        /* Ugh, memmove - sadly necessary, also beware that we might be
     1799         * moving data around within this packet, so ordering is important.
     1800         */
     1801        memmove(packet->payload, data, (size_t)len);
     1802        memmove(packet->header, &hdr, sizeof(hdr));
    17981803        packet->type=pcap_linktype_to_rt(libtrace_to_pcap_linktype(linktype));
    17991804
Note: See TracChangeset for help on using the changeset viewer.