Changeset - 193a625a7915
[Not reviewed]
Mehmet Aslan - 7 years ago 2019-01-27 10:22:24
aaslan-mehmet@hotmail.com
memory leak in ascii reader fixed
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/asciireader.cpp
Show inline comments
 
@@ -106,48 +106,49 @@ void AsciiReader::onDataReady()
 
        // system CR is converted to LF for some reason. This causes
 
        // empty lines in the input when the port is just opened.
 
        if (line.isEmpty())
 
        {
 
            continue;
 
        }
 

	
 
        const SamplePack* samples = parseLine(line);
 
        if (samples != nullptr) {
 
            // update number of channels if in auto mode
 
            if (autoNumOfChannels ) {
 
                unsigned nc = samples->numChannels();
 
                if (nc != _numChannels) {
 
                    _numChannels = nc;
 
                    updateNumChannels();
 
                    // TODO: is `numOfChannelsChanged` signal still used?
 
                    emit numOfChannelsChanged(nc);
 
                }
 
            }
 

	
 
            Q_ASSERT(samples->numChannels() == _numChannels);
 

	
 
            // commit data
 
            feedOut(*samples);
 
            delete samples;
 
        }
 
    }
 
}
 

	
 
SamplePack* AsciiReader::parseLine(const QString& line) const
 
{
 
    auto separatedValues = line.split(delimiter, QString::SkipEmptyParts);
 
    unsigned numComingChannels = separatedValues.length();
 

	
 
    // check number of channels (skipped if auto num channels is enabled)
 
    if ((!numComingChannels) || (!autoNumOfChannels && numComingChannels != _numChannels))
 
    {
 
        qWarning() << "Line parsing error: invalid number of channels!";
 
        qWarning() << "Read line: " << line;
 
        return nullptr;
 
    }
 

	
 
    // parse data per channel
 
    auto samples = new SamplePack(1, numComingChannels);
 
    for (unsigned ci = 0; ci < numComingChannels; ci++)
 
    {
 
        bool ok;
 
        samples->data(ci)[0] = separatedValues[ci].toDouble(&ok);
 
        if (!ok)
0 comments (0 inline, 0 general)