pellegre / libcrafter

A high level C++ network packet sniffing and crafting library.
298 stars 88 forks source link

Fix memory leak on Layer's copy constructor. #42

Closed mfontanini closed 8 years ago

mfontanini commented 8 years ago

When copy-constructing a Layer, if the object being copied's layer sizei s 0, raw_layer is intialized by using a 0 size allocation. However, Layer::~Layer only deletes raw_layer if the size > 0. In this case, the size is 0, so it won't ever be deleted.

This was happening specifically if you copy constructed a RawLayer, since the header size is 0. If you run it on valgrind you won't see any leaks though, since it seems like 0 size calls to operator new[] aren't marked as leaks.

I modified Layer so it always calls delete[] on raw_data, regardless of what the size is. Moreover, it only allocates data for raw_layer on the copy constructor if the size is > 0.

pellegre commented 8 years ago

Thanks!