Skip to content

Fix memory leak in str_replace.#133

Merged
manugarg merged 2 commits intomasterfrom
fix_96
Apr 13, 2022
Merged

Fix memory leak in str_replace.#133
manugarg merged 2 commits intomasterfrom
fix_96

Conversation

@manugarg
Copy link
Owner

No description provided.

@manugarg manugarg linked an issue Mar 25, 2022 that may be closed by this pull request
@fralken
Copy link

fralken commented Apr 12, 2022

Hello,
imo this PR is not correct, i.e., free(tmporig); doesn't work since tmporig has moved and doesn't point to the start of the buffer.
Since the buffer pointed by orig parameter is not modified inside the function, there is no need to duplicate it.
So, instead of doing

    char *tmporig = malloc(strlen(orig) + 1); // Copy of orig that we work with
    tmporig = strcpy(tmporig, orig);

it should be enough doing instead

    char *tmporig = orig;

so there is no need to perform a free() in the end, and no memory leak is created.

@manugarg
Copy link
Owner Author

Thanks for catching this, @fralken! You're correct. As I said on the issue comment, I think we can skip copying the original string completely. Updated PR to reflect that.

We don't need to create copy of the original string.
@manugarg manugarg merged commit f013613 into master Apr 13, 2022
@manugarg manugarg deleted the fix_96 branch April 13, 2022 21:28
@fralken
Copy link

fralken commented Apr 25, 2022

Hello, are you planning to publish a new release with these fixes?

@manugarg
Copy link
Owner Author

Released - v.1.4.0.

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.

Memory leak in pac_utils.h

2 participants