Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastBuffer not copy or move safe #19

Closed
sloretz opened this issue May 15, 2018 · 2 comments
Closed

FastBuffer not copy or move safe #19

sloretz opened this issue May 15, 2018 · 2 comments

Comments

@sloretz
Copy link
Contributor

sloretz commented May 15, 2018

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;
}
@richiware
Copy link
Member

Commit 9261c84 solves this issue.

@MiguelCompany
Copy link
Member

This was solved long ago. Closing issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants