csv-parser icon indicating copy to clipboard operation
csv-parser copied to clipboard

Segmentation Fault in csv::internals::ThreadSafeDeque<csv::CSVRow>::~ThreadSafeDeque

Open tonjif opened this issue 4 years ago • 1 comments
trafficstars

I have been using CSVReader in a function like this:

void load_trajectory_dataset(std::string& trajectory_dataset_path, TrajectoryDataset& trajectory_dataset) {
    csv::CSVFormat format;
    format.delimiter(',')
        .header_row(0);
    
    /* Create Reader */
    csv::CSVReader reader(trajectory_dataset_path, format);
    
    /* Value for each row */
    integer_type user;
    floating_point_type latitude, longitude, timestamp;
    
    /* Iterate all rows */
    for (csv::CSVRow& row: reader) {
        user = row["user"].get<integer_type>();
        latitude = row["latitude"].get<floating_point_type>();
        longitude = row["longitude"].get<floating_point_type>();
        timestamp = row["timestamp"].get<floating_point_type>();
        
        /* Save information */
        trajectory_dataset[user].emplace_back(latitude, longitude, timestamp);
    }
}

When returning from this function, a Segmentation Fault is encountered in the destructor of csv::internals::ThreadSafeDequecsv::CSVRow, csv::internals::ThreadSafeDequecsv::CSVRow::~ThreadSafeDeque. The LLDB back trace is as follows:

(lldb) bt
* thread #1, name = 'a.out', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #0: 0x0000000000000000
    frame #1: 0x00000000004179e8 a.out`csv::internals::ThreadSafeDeque<csv::CSVRow>::~ThreadSafeDeque(this=0x00000000006c2aa0) at csv.hpp:5903:15
    frame #2: 0x00000000004228ab a.out`std::default_delete<csv::internals::ThreadSafeDeque<csv::CSVRow> >::operator(this=0x00007fffffffc600, __ptr=0x00000000006c2aa0)(csv::internals::ThreadSafeDeque<csv::CSVRow>*) const at unique_ptr.h:81:2
    frame #3: 0x00000000004146bd a.out`std::unique_ptr<csv::internals::ThreadSafeDeque<csv::CSVRow>, std::default_delete<csv::internals::ThreadSafeDeque<csv::CSVRow> > >::~unique_ptr(this=0x00007fffffffc600) at unique_ptr.h:292:4
    frame #4: 0x0000000000408af0 a.out`csv::CSVReader::~CSVReader(this=0x00007fffffffc590) at csv.hpp:6320:9
    frame #5: 0x0000000000405979 a.out`load_trajectory_dataset(trajectory_dataset_path=error: summary string parsing error, trajectory_dataset=0x00000000006a4740) at input_output.hpp:34:1
    frame #6: 0x00000000004065ad a.out`main(argc=5, argv=0x00007fffffffce08) at calculate_and_write_k_nn_trajectory_similarity.cpp:127:6
    frame #7: 0x000000000050ef60 a.out`__libc_start_main + 1168
    frame #8: 0x000000000040532e a.out`_start + 46

I was wondering whether pointers were used in csv::internals::ThreadSafeDeque, but I couldn't find any when I read csv::internals::ThreadSafeDeque at csv.hpp:5903:15 . What else could be the cause of the invalid address?

tonjif avatar May 16 '21 01:05 tonjif

Thanks for reporting this. ThreadSafeDeque is a generic container, and in this case it is used to hold CSVRow objects, which do contain pointers.

vincentlaucsb avatar May 24 '21 06:05 vincentlaucsb