Skip to content

branch-4.0: [Fix](geo) fix memory leak in geo #58004#58365

Merged
yiguolei merged 1 commit intobranch-4.0from
auto-pick-58004-branch-4.0
Nov 26, 2025
Merged

branch-4.0: [Fix](geo) fix memory leak in geo #58004#58365
yiguolei merged 1 commit intobranch-4.0from
auto-pick-58004-branch-4.0

Conversation

@github-actions
Copy link
Contributor

Cherry-picked from #58004

The current `WkbParse::parse_wkb` function has a memory leak issue
caused by unreleased pointers, the pseudocode is as follows:
```cpp
struct WktContext {
    Shape* shape;
    Status parse_status;
};

void init (WktContext& ctx) {
    ctx.shape = (Shape*) malloc(sizeof(Shape));
    ctx.parse_status == GEO_PARSE_OK;
}

void parse_wkt(Shape** to_shape) {
    WktContext ctx;
    init(ctx);

    auto status = wkt_parse();
    if (status == GEO_PARSE_OK) {
        *to_shape = ctx.shape;
    } else {
        ctx.parse_status = GEO_PARSE_ERROR;
        // Here ctx.shape is not deleted, leading to memory leak
    }
}
```

This PR replaces some raw pointers in geo with `unique_ptr` to enhance
memory management safety and reduce potential memory leaks issues.
@github-actions github-actions bot requested a review from yiguolei as a code owner November 25, 2025 13:25
@hello-stephen
Copy link
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@dataroaring dataroaring reopened this Nov 25, 2025
@hello-stephen
Copy link
Contributor

run buildall

@hello-stephen
Copy link
Contributor

BE UT Coverage Report

Increment line coverage 83.56% (61/73) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 52.73% (18180/34479)
Line Coverage 38.08% (165400/434368)
Region Coverage 33.11% (128441/387971)
Branch Coverage 33.90% (55346/163265)

@yiguolei yiguolei merged commit 3fcfd66 into branch-4.0 Nov 26, 2025
24 of 27 checks passed
@github-actions github-actions bot deleted the auto-pick-58004-branch-4.0 branch November 26, 2025 01:22
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.

4 participants

Comments