Skip to content

Removed usage of variable length arrays, fixed memory leaks#2400

Merged
jwillemsen merged 2 commits into
DOCGroup:masterfrom
jwillemsen:jwi-vararray
Jun 24, 2025
Merged

Removed usage of variable length arrays, fixed memory leaks#2400
jwillemsen merged 2 commits into
DOCGroup:masterfrom
jwillemsen:jwi-vararray

Conversation

@jwillemsen
Copy link
Copy Markdown
Member

@jwillemsen jwillemsen commented Jun 12, 2025

* ACE/ace/Svc_Conf_Lexer.cpp:

Summary by CodeRabbit

  • Refactor
    • Improved memory management by replacing macro-based temporary string allocation with modern, safer heap allocation using smart pointers. This enhances code reliability and maintainability without affecting user-facing features.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 12, 2025

Walkthrough

The code in Svc_Conf_Lexer.cpp was updated to remove the ACE_TEMPORARY_STRING macro and its conditional logic. Temporary string buffers are now uniformly allocated using std::unique_ptr<char[]>, with explicit null-termination after copying data. No public or exported entity declarations were altered.

Changes

File(s) Change Summary
ACE/ace/Svc_Conf_Lexer.cpp Removed macro-based buffer allocation; now uses std::unique_ptr for temporary string buffers with explicit null-termination.

Poem

A macro retires, its work now complete,
Unique pointers step in, so tidy and neat.
No more conditionals, no stack or heap fight,
Just RAII magic, making things right.
With buffers now safer, the code hops along—
A rabbit’s delight, in memory strong! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch jwi-vararray
  • Post Copyable Unit Tests in Comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jwillemsen
Copy link
Copy Markdown
Member Author

clang20 does always give a warning now when a variable length array is used

@jwillemsen jwillemsen requested a review from mitza-oci June 12, 2025 09:37
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
ACE/ace/Svc_Conf_Lexer.cpp (1)

20-22: ⚠️ Potential issue

<memory> must be included unconditionally

std::unique_ptr / std::make_unique are now used for all compilers, but <memory> is only included when __GNUG__ is not defined.
With GCC/Clang this header may be transitively included today, yet that is an implementation detail and breaks clean‐room builds or older libstdc++ versions.

-#if !defined (__GNUG__)
-# include <memory>
-#endif
+#include <memory>  // needed for std::unique_ptr / std::make_unique
🧹 Nitpick comments (1)
ACE/ace/Svc_Conf_Lexer.cpp (1)

411-416: Avoid per-token heap allocation in the hot path

Replacing the VLA with

std::unique_ptr<char[]> str_bufp = std::make_unique<char[]>(size);

creates a heap allocation for every identifier scanned.
For large service config files this is a measurable regression compared to the former stack allocation.

Optional, but recommended:

  1. Reserve a small fixed stack buffer (e.g. char local[256]) and fall back to std::unique_ptr only when size > sizeof local.
  2. Alternatively, use std::string_view and do the keyword comparisons directly on the input buffer, eliminating the copy completely.

No functional change – purely a performance / allocation-pressure optimisation.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e33dd50 and b0d6b70.

📒 Files selected for processing (1)
  • ACE/ace/Svc_Conf_Lexer.cpp (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (21)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: alpine-3.18
  • GitHub Check: ubuntu-24.04 g++
  • GitHub Check: ubuntu-24.04 g++-10 wchar
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e compact
  • GitHub Check: ubuntu-24.04 g++-10 CORBA/e micro
  • GitHub Check: ubuntu-24.04 g++-10 ACE for TAO
  • GitHub Check: ubuntu-24.04 clang++-14
  • GitHub Check: VS2022Debug64Cxx17
  • GitHub Check: ubuntu-24.04 g++-12
  • GitHub Check: ubuntu-22.04 g++-10
  • GitHub Check: ubuntu-24.04 g++-11
  • GitHub Check: ubuntu-24.04 g++-14
  • GitHub Check: ubuntu-22.04 clang++-13
  • GitHub Check: ubuntu-22.04 g++-9
  • GitHub Check: ubuntu-24.04 clang++-16
  • GitHub Check: ubuntu-24.04 g++-13
  • GitHub Check: ubuntu-22.04 clang++-12
  • GitHub Check: windows-2022 vs2022
  • GitHub Check: ubuntu-24.04 clang++-15
  • GitHub Check: MINGW64-gcc
🔇 Additional comments (1)
ACE/ace/Svc_Conf_Lexer.cpp (1)

411-416: std::make_unique requires C++14

ACE still supports C++11 tool-chains in several environments. std::make_unique is C++14; compilation will fail with C++11.
If C++14 is not guaranteed, fall back to explicit construction:

-std::unique_ptr<char[]> str_bufp = std::make_unique<char[]>(size);
+std::unique_ptr<char[]> str_bufp(new char[size]);

Would you confirm the minimum C++ standard ACE targets for this branch?

    * ACE/ace/Svc_Conf_Lexer.cpp:
@jwillemsen
Copy link
Copy Markdown
Member Author

@coderabbitai full review

@jwillemsen jwillemsen changed the title Removed usage of variable length arrays, these are a gcc/clang extension Removed usage of variable length arrays, fixed memory leaks in non gcc case Jun 23, 2025
@jwillemsen jwillemsen changed the title Removed usage of variable length arrays, fixed memory leaks in non gcc case Removed usage of variable length arrays, fixed memory leaks Jun 23, 2025
@mitza-oci
Copy link
Copy Markdown
Member

std::string can do the same thing (small string optimization) -- would it be better to use it directly?

@jwillemsen
Copy link
Copy Markdown
Member Author

std::string can do the same thing (small string optimization) -- would it be better to use it directly?

I just wanted to make a simple change to get rid of a warning with a compiler I am testing, introducing std::string is something for a later moment in time

@jwillemsen jwillemsen merged commit 683c71a into DOCGroup:master Jun 24, 2025
43 of 45 checks passed
@jwillemsen jwillemsen deleted the jwi-vararray branch June 24, 2025 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants