Skip to content

Commit f92cad1

Browse files
fix mem error/leak
1 parent 360ff21 commit f92cad1

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

pc/pub_stats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void pub_stats::get_quartiles( const uint32_t *hist, uint32_t q[4] ) const
6464
unsigned j=0;
6565
for( uint64_t i=0; i != num_buckets && j != 4; ++i ) {
6666
cum += hist[i];
67-
while ( cum >= pct[j]*num_recv_ && j != 4) {
67+
while ( j != 4 && cum >= pct[j]*num_recv_ ) {
6868
q[j++] = i;
6969
}
7070
}

pc/request.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,14 @@ product::product( const pub_key& acc )
13611361
sreq_->set_sub( this );
13621362
}
13631363

1364+
product::~product()
1365+
{
1366+
for( price *ptr: pvec_ ) {
1367+
delete ptr;
1368+
}
1369+
pvec_.clear();
1370+
}
1371+
13641372
pub_key *product::get_account()
13651373
{
13661374
return &acc_;

pc/request.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ namespace pc
496496
public:
497497

498498
product( const pub_key& );
499+
virtual ~product();
499500
void reset();
500501
void submit() override;
501502
void on_response( rpc::get_account_info * ) override;

pctest/test_publish.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class test_connect : public pc::manager_sub
1111
{
1212
public:
1313
test_connect();
14-
virtual ~test_connect();
1514

1615
// on connection to (but not initialization) solana validator
1716
void on_connect( pc::manager * ) override;
@@ -31,6 +30,8 @@ class test_connect : public pc::manager_sub
3130
// get price from map
3231
pc::price *get_price( const std::string& ) const;
3332

33+
void teardown();
34+
3435
private:
3536
test_publish *pub1_; // SYMBOL1 publisher
3637
test_publish *pub2_; // SYMBOL2 publisher
@@ -94,10 +95,11 @@ test_connect::test_connect()
9495
{
9596
}
9697

97-
test_connect::~test_connect()
98+
void test_connect::teardown()
9899
{
99100
delete pub1_;
100101
delete pub2_;
102+
pub1_ = pub2_ = nullptr;
101103
}
102104

103105
void test_connect::on_connect( pc::manager * )
@@ -388,6 +390,8 @@ int main(int argc, char** argv)
388390
std::cerr << "test_publish: " << mgr.get_err_msg() << std::endl;
389391
retcode = 1;
390392
}
393+
sub.teardown();
394+
391395
return retcode;
392396
}
393397

0 commit comments

Comments
 (0)