Skip to content

FastBuffer not copy or move safe #19

@sloretz

Description

@sloretz

eprosima::fastcdr::FastBuffer is not copy or move safe. It does not implement nor delete the default copy constructor, copy assignment operator, move constructor, or move assignment operator. If any one of those is used with an allocated buffer then the internal buffer will be freed twice.

#include <utility>

#include "fastcdr/FastBuffer.h"

int main()
{
  // Copy assignment
  {
    eprosima::fastcdr::FastBuffer buffer1;
    // Uncommenting this line causes double free at scope exit
    // buffer1.resize(1000);
    eprosima::fastcdr::FastBuffer buffer2 = buffer1;
  }

  // Copy constructor
  {
    eprosima::fastcdr::FastBuffer buffer1;
    // Uncommenting this line causes double free at scope exit
    // buffer1.resize(1000);
    eprosima::fastcdr::FastBuffer buffer2(buffer1);
  }

  // Move assignment
  {
    eprosima::fastcdr::FastBuffer buffer1;
    // Uncommenting this line causes double free at scope exit
    // buffer1.resize(1000);
    eprosima::fastcdr::FastBuffer buffer2 = std::move(buffer1);
  }

  // Move constructor
  {
    eprosima::fastcdr::FastBuffer buffer1;
    // Uncommenting this line causes double free at scope exit
    // buffer1.resize(1000);
    eprosima::fastcdr::FastBuffer buffer2(std::move(buffer1));
  }

  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions