Hi, I'm not familiar with this code.
Looking at it now though I see some things that look odd to me. First, struct CacheEntry inherits from NABasicObject. If I understand export/NABasicObject.h correctly, we should use "delete" on it, and not NADELETE. Another thing I wonder about is CacheEntry has its member "KeyDataPair data_;". The destructor for struct KeyDataPair does nothing; note that the only members of struct KeyDataPair are pointers. So, calling ~KeyDataPair() at line 1357 appears to be harmless. I agree with you that it is also redundant. Dave -----Original Message----- From: Zhu, Wen-Jun <[email protected]> Sent: Saturday, November 10, 2018 12:49 AM To: [email protected] Subject: destructor has been called twice? Hi, When I read code in core/sql/sqlcomp/QCache.h, I found that: 1349 // removes the element at iterator position pos and 1350 // returns the position of the next element 1351 iterator erase(iterator pos) 1352 { 1353 if (pos == end()) return end(); 1354 iterator tmp = (iterator)(pos.node_->next_); 1355 pos.node_->prev_->next_ = pos.node_->next_; 1356 pos.node_->next_->prev_ = pos.node_->prev_; 1357 pos.node_->data_.~KeyDataPair(); // destroy data_ 1358 putNode(pos.node_); 1359 --length_; 1360 return tmp; 1361 } 1278 void putNode(CacheEntry* p) { 1279 NADELETE(p,CacheEntry,heap_); // implicitly calls p.data_.~KeyDataPair() 1280 } The data in that node had been destructed twice. So this is a problem. I suggestion is to remove the first destruction, i.e., do not call the destruction function explicitly. And the function name `putNode` is not so accurate. How do you find it? Regards, Wenjun Zhu
