forked from apache/pulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cpp: fix reference leak when reader create (apache#7793)
### Motivation User reports a valgrind error for `client::createReader` method: ``` ==23308== 284,826 (160 direct, 284,666 indirect) bytes in 1 blocks are definitely lost in loss record 113 of 113 ==23308== at 0x4C2A593: operator new(unsigned long) (vg_replace_malloc.c:344) ==23308== by 0x5303B4A: allocate (new_allocator.h:104) ==23308== by 0x5303B4A: allocate (alloc_traits.h:351) ==23308== by 0x5303B4A: __shared_count<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:499) ==23308== by 0x5303B4A: __shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr_base.h:957) ==23308== by 0x5303B4A: shared_ptr<std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:316) ==23308== by 0x5303B4A: allocate_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader>, std::allocator<pulsar::InternalState<pulsar::Result, pulsar::Reader> > > (shared_ptr.h:598) ==23308== by 0x5303B4A: make_shared<pulsar::InternalState<pulsar::Result, pulsar::Reader> > (shared_ptr.h:614) ==23308== by 0x5303B4A: Promise (Future.h:91) ==23308== by 0x5303B4A: pulsar::Client::createReader(std::string const&, pulsar::MessageId const&, pulsar::ReaderConfiguration const&, pulsar::Reader&) (Client.cc:142) ==23308== by 0x401DDB: main (pulsarReader.cpp:92) ==23308== ``` It seems the `ReaderImpl` has been tracked twice when call WaitForCallbackValue. this PR is to fix the issue. ### Modifications - fix WaitForCallbackValue which is changed in PR apache#3484. - add test for the reference issue. ### Verifying this change ut passed. valgrind found no issue: ``` ==14758== LEAK SUMMARY: ==14758== definitely lost: 0 bytes in 0 blocks ==14758== indirectly lost: 0 bytes in 0 blocks ==14758== possibly lost: 0 bytes in 0 blocks ==14758== still reachable: 12,621 bytes in 145 blocks ==14758== suppressed: 0 bytes in 0 blocks ==14758== ==14758== For lists of detected and suppressed errors, rerun with: -s ==14758== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) ```
- Loading branch information
Showing
5 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
#include "lib/ReaderImpl.h" | ||
#include <string> | ||
|
||
using std::string; | ||
|
||
namespace pulsar { | ||
class ReaderTest { | ||
public: | ||
static ConsumerImplPtr getConsumer(const Reader& reader) { return reader.impl_->getConsumer(); } | ||
static ReaderImplWeakPtr getReaderImplWeakPtr(const Reader& reader) { | ||
return reader.impl_->getReaderImplWeakPtr(); | ||
} | ||
}; | ||
} // namespace pulsar |