-
Notifications
You must be signed in to change notification settings - Fork 2
leaky function coverity testing -- DO NOT MERGE #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -234,6 +234,16 @@ int drop_root(void) | |||||||||||||||||||||||||||||||||
| return retval; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| void leaky_function(void) { | ||||||||||||||||||||||||||||||||||
| char *p = (char *)malloc(100); // allocated but never freed -> leak | ||||||||||||||||||||||||||||||||||
| if (!p) { | ||||||||||||||||||||||||||||||||||
| perror("malloc"); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| strcpy(p, "This buffer is intentionally leaked."); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+239
to
+243
|
||||||||||||||||||||||||||||||||||
| if (!p) { | |
| perror("malloc"); | |
| return; | |
| } | |
| strcpy(p, "This buffer is intentionally leaked."); | |
| errno_t rc; | |
| if (!p) { | |
| perror("malloc"); | |
| return; | |
| } | |
| rc = strcpy_s(p, 100, "This buffer is intentionally leaked."); | |
| if (rc != EOK) { | |
| /* If the copy fails, avoid using an uninitialized buffer. */ | |
| free(p); | |
| return; | |
| } |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function serves no purpose in the application and should be removed. It allocates memory, copies a string into it, but never uses the result or returns any value. This appears to be dead code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverity Issue - Resource leak
Variable "p" going out of scope leaks the storage it points to.
High Impact, CWE-404
RESOURCE_LEAK
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling leaky_function introduces a memory leak at program startup. This call should be removed as it serves no functional purpose and wastes system resources.
| leaky_function(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: allocated memory is never freed. The malloc'ed buffer should be freed before the function returns, either after use or in the error path if needed.