Skip to content

There is a memory leak defect at line 2214 in /php-src/main/streams/streams.c. #15026

Closed

Description

@LuMingYinDetect

Description

A pointer variable named resolved_path is defined at line 2186 in the file /php-src/main/streams/streams.c. This variable is allocated a block of dynamic memory via the function php_resolve_path at line 2205. When the if statement at line 2213 evaluates to true, the function returns at line 2214. However, unlike at line 2224 where the dynamically allocated memory pointed to by resolved_path is freed before returning, in this case, it leads to a memory leak defect, as illustrated below:
https://github.com/LuMingYinDetect/php_defects/blob/main/php_3.png

PHP Version

PHP 8.4.0

Operating System

Ubuntu 22.04

Activity

  1. ndossche commented on Jul 19, 2024

    @ndossche
    Member

    Hmm, isn't resolved_path NULL when EG(exception) is set? Otherwise how could we have an exception and a path at the same time?

  2. LuMingYinDetect commented on Jul 19, 2024

    @LuMingYinDetect
    Author

    Hmm, isn't resolved_path NULL when EG(exception) is set? Otherwise how could we have an exception and a path at the same time?

    Thank you for your prompt reply! I didn't notice this issue when verifying the defect report; it should be a false alarm.

  3. ndossche commented on Jul 19, 2024

    @ndossche
    Member

    No problem, thanks for the other reports btw.
    I have opened a PR to add an assertion that the path is NULL in case an exception was thrown. This should make the developer intent clear and prevent further reports of this.

  4. LuMingYinDetect commented on Jul 19, 2024

    @LuMingYinDetect
    Author

    No problem, thanks for the other reports btw. I have opened a PR to add an assertion that the path is NULL in case an exception was thrown. This should make the developer intent clear and prevent further reports of this.

    I am happy to contribute to PHP. In fact, receiving prompt responses from developers helps us improve our static analysis tool more effectively, ensuring better outcomes.Currently, our static analysis tool still has some bugs. Thank you very much for your feedback on false positives!

  5. ndossche commented on Sep 16, 2024

    @ndossche
    Member

    @LuMingYinDetect Turns out this is in fact a true positive, see #15908. I'll make sure to credit you in the test file.

  6. added a commit that references this issue on Sep 16, 2024
  7. LuMingYinDetect commented on Sep 17, 2024

    @LuMingYinDetect
    Author

    事实证明这实际上是一个真正的阳性,请参阅 #15908。我一定会在测试文件中注明你的功劳。

    Thank you for your patient response! We greatly appreciate your affirmation of our work!

  8. added 3 commits that reference this issue on Sep 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions