fix mem leak

This commit is contained in:
badaix 2019-11-17 15:14:55 +01:00
parent dbd0b018e2
commit 211b5afdd3
3 changed files with 19 additions and 7 deletions

View file

@ -30,9 +30,11 @@ namespace msg
class CodecHeader : public BaseMessage class CodecHeader : public BaseMessage
{ {
public: public:
CodecHeader(const std::string& codecName = "", size_t size = 0) : BaseMessage(message_type::kCodecHeader), payloadSize(size), codec(codecName) CodecHeader(const std::string& codecName = "", size_t size = 0)
: BaseMessage(message_type::kCodecHeader), payloadSize(size), payload(nullptr), codec(codecName)
{ {
payload = (char*)malloc(size); if (size > 0)
payload = (char*)malloc(size * sizeof(char));
} }
~CodecHeader() override ~CodecHeader() override
@ -62,7 +64,7 @@ protected:
writeVal(stream, payload, payloadSize); writeVal(stream, payload, payloadSize);
} }
}; };
} } // namespace msg
#endif #endif

View file

@ -50,6 +50,15 @@ public:
~PcmChunk() override = default; ~PcmChunk() override = default;
template <class Rep, class Period>
int readFrames(void* outputBuffer, const std::chrono::duration<Rep, Period>& duration)
{
auto us = std::chrono::microseconds(duration).count();
auto frames = (us * 48000) / std::micro::den;
// return readFrames(outputBuffer, (us * 48000) / std::micro::den);
return frames;
}
int readFrames(void* outputBuffer, size_t frameCount) int readFrames(void* outputBuffer, size_t frameCount)
{ {
// logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize) << ", idx: " << idx;// << std::endl; // logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize) << ", idx: " << idx;// << std::endl;
@ -123,6 +132,6 @@ public:
private: private:
uint32_t idx_; uint32_t idx_;
}; };
} } // namespace msg
#endif #endif

View file

@ -39,9 +39,10 @@ namespace msg
class WireChunk : public BaseMessage class WireChunk : public BaseMessage
{ {
public: public:
WireChunk(size_t size = 0) : BaseMessage(message_type::kWireChunk), payloadSize(size) WireChunk(size_t size = 0) : BaseMessage(message_type::kWireChunk), payloadSize(size), payload(nullptr)
{ {
payload = (char*)malloc(size); if (size > 0)
payload = (char*)malloc(size * sizeof(char));
} }
WireChunk(const WireChunk& wireChunk) : BaseMessage(message_type::kWireChunk), timestamp(wireChunk.timestamp), payloadSize(wireChunk.payloadSize) WireChunk(const WireChunk& wireChunk) : BaseMessage(message_type::kWireChunk), timestamp(wireChunk.timestamp), payloadSize(wireChunk.payloadSize)
@ -84,7 +85,7 @@ protected:
writeVal(stream, payload, payloadSize); writeVal(stream, payload, payloadSize);
} }
}; };
} } // namespace msg
#endif #endif