rigtorp / MPMCQueue

A bounded multi-producer multi-consumer concurrent queue written in C++11
MIT License
1.15k stars 159 forks source link

Fix memory leak on MPMCQueue's construction with null capacity. #2

Closed Akkarinn closed 7 years ago

Akkarinn commented 7 years ago

If given 'capacity' is < 1 you create a memory leak by throwing after memory allocation since '~MPMCQueue' will not be called. I suggest to move the check in a nested static member function called before 'slots_' initialization.

rigtorp commented 7 years ago

@Akkarinn Thanks for finding this bug!

What do you think about this solution? https://github.com/rigtorp/MPMCQueue/commit/5bb796fe009ad04c9eae57d0e2289ffb8a7358d1

Akkarinn commented 7 years ago

@rigtorp Your update 5bb796f is better than my proposal :+1:

rigtorp commented 7 years ago

@Akkarinn I fixed the same bug here: https://github.com/rigtorp/SPSCQueue/commit/97ca6b6b254630093bc52db51cc3063217a26987