Skip to content

Commit f6a7bdf

Browse files
author
Thiemo Wiedemeyer
committed
fixed memory leak due to unknown state of packet pipeline pointer.
1 parent 9a70d5e commit f6a7bdf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

examples/protonect/src/libfreenect2.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
678678
if(idx >= num_devices)
679679
{
680680
std::cout << "[Freenect2Impl] requested device " << idx << " is not connected!" << std::endl;
681+
delete pipeline;
681682
return device;
682683
}
683684

@@ -688,6 +689,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
688689
{
689690
std::cout << "[Freenect2Impl] failed to get device " << PrintBusAndDevice(dev.dev)
690691
<< " (the device may already be open)" << std::endl;
692+
delete pipeline;
691693
return device;
692694
}
693695

@@ -696,6 +698,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
696698
if(r != LIBUSB_SUCCESS)
697699
{
698700
std::cout << "[Freenect2Impl] failed to open Kinect v2 " << PrintBusAndDevice(dev.dev) << "!" << std::endl;
701+
delete pipeline;
699702
return device;
700703
}
701704

@@ -733,6 +736,7 @@ Freenect2Device *Freenect2::openDevice(int idx, const PacketPipeline *pipeline,
733736
else if(r != LIBUSB_SUCCESS)
734737
{
735738
std::cout << "[Freenect2Impl] failed to reset Kinect v2 " << PrintBusAndDevice(dev.dev) << "!" << std::endl;
739+
delete pipeline;
736740
return device;
737741
}
738742
}
@@ -765,11 +769,11 @@ Freenect2Device *Freenect2::openDevice(const std::string &serial, const PacketPi
765769
{
766770
if(impl_->enumerated_devices_[idx].serial == serial)
767771
{
768-
device = openDevice(idx, pipeline);
769-
break;
772+
return openDevice(idx, pipeline);
770773
}
771774
}
772775

776+
delete pipeline;
773777
return device;
774778
}
775779

0 commit comments

Comments
 (0)