Skip to content

refactor: replace raw pointer with unique_ptr in NotificationConsumer#1212

Open
xq9mend wants to merge 1 commit into
sonic-net:masterfrom
xq9mend:fix/notificationconsumer-unique-ptr
Open

refactor: replace raw pointer with unique_ptr in NotificationConsumer#1212
xq9mend wants to merge 1 commit into
sonic-net:masterfrom
xq9mend:fix/notificationconsumer-unique-ptr

Conversation

@xq9mend

@xq9mend xq9mend commented Jun 19, 2026

Copy link
Copy Markdown

What

Replace raw DBConnector* member m_subscribe with std::unique_ptr<DBConnector> in NotificationConsumer.

Why

The raw pointer required manual delete in two separate places — the destructor and the constructor catch block. This pattern is error-prone and exception-unsafe: if a future change adds an early return or throws between allocation and cleanup, the pointer leaks.

How

  • Remove explicit destructor — compiler-generated handles cleanup via unique_ptr
  • Remove delete m_subscribe from catch block — automatic on reassignment
  • Remove NULL initializer — unique_ptr default-constructs to nullptr
  • Replace new DBConnector(...) with std::make_unique<DBConnector>(...) in subscribe()
  • Add .get() where raw pointer is passed to RedisReply constructor
  • Add <memory> include to both .cpp and .h

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines will not run the associated pipelines, because the pull request was updated after the run command was issued. Review the pull request again and issue a new run command.

@xq9mend
xq9mend force-pushed the fix/notificationconsumer-unique-ptr branch from 9a9cadf to 8ab7f45 Compare June 19, 2026 07:46
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xq9mend
xq9mend force-pushed the fix/notificationconsumer-unique-ptr branch from 8ab7f45 to 54bb184 Compare June 19, 2026 20:35
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@xq9mend

xq9mend commented Jun 20, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

No Azure DevOps builds found for #1212.

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

m_subscribe was a raw DBConnector* requiring manual delete in two places:
the destructor and the constructor's catch block. This is error-prone and
exception-unsafe.

Replace with std::unique_ptr<DBConnector>:
- Remove explicit destructor (compiler-generated handles cleanup)
- Remove delete in catch block (reset is automatic on reassignment)
- Remove NULL initializer (unique_ptr default-constructs to nullptr)
- Use std::make_unique<DBConnector>() in subscribe()
- Add .get() where raw pointer is passed to RedisReply constructor

Test: add SubscribeViaUnixSocket to ntf_ut.cpp to cover the unix-socket
branch of subscribe() (all previous tests used TCP connections).

Signed-off-by: xq9mend <xq9mend@users.noreply.github.com>
@xq9mend
xq9mend force-pushed the fix/notificationconsumer-unique-ptr branch from 1ee2c80 to ccfec8b Compare June 20, 2026 09:20
@xq9mend

xq9mend commented Jun 20, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

No Azure DevOps builds found for #1212.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@xq9mend

xq9mend commented Jun 20, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1144141:

✅Stage BuildSairedis:

  • Job amd64: retried.

@xq9mend

xq9mend commented Jun 21, 2026

Copy link
Copy Markdown
Author

/azpw run Azure.sonic-swss-common

@mssonicbld

Copy link
Copy Markdown
Collaborator

⚠️ Notice: /azpw run only runs failed jobs now. If you want to trigger a whole pipline run, please rebase your branch or close and reopen the PR.
💡 Tip: You can also use /azpw retry to retry failed jobs directly.

Retrying failed(or canceled) jobs...

@mssonicbld

Copy link
Copy Markdown
Collaborator

Retrying failed(or canceled) stages in build 1144141:

✅Stage BuildSwss:

  • Job amd64: retried.

@xq9mend

xq9mend commented Jul 4, 2026

Copy link
Copy Markdown
Author

/azp run Azure.sonic-swss-common

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 1212 in repo sonic-net/sonic-swss-common

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants