Skip to content

Comments

leaky function coverity testing -- DO NOT MERGE#24

Open
SanthoshGujulvajagadeesh wants to merge 1 commit intodevelopfrom
raise_pr_coverity_testing
Open

leaky function coverity testing -- DO NOT MERGE#24
SanthoshGujulvajagadeesh wants to merge 1 commit intodevelopfrom
raise_pr_coverity_testing

Conversation

@SanthoshGujulvajagadeesh

No description provided.

Copilot AI review requested due to automatic review settings February 4, 2026 08:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds test code with intentional memory leaks and security vulnerabilities for Coverity static analysis testing. As indicated by the title "DO NOT MERGE", this is not intended for production use.

Changes:

  • Adds a new function leaky_function() with intentional memory leak and unsafe strcpy usage
  • Calls the leaky function in main(), introducing a memory leak on every program execution

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}

void leaky_function(void) {
char *p = (char *)malloc(100); // allocated but never freed -> leak
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Memory leak: malloc allocates 100 bytes but the memory is never freed. This will cause a memory leak each time the function is called.

Copilot uses AI. Check for mistakes.
perror("malloc");
return;
}
strcpy(p, "This buffer is intentionally leaked.");
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

strcpy is unsafe and can lead to buffer overflows. Consider using a safer alternative like strncpy, strlcpy, or the safec library functions that are already used in this codebase (as seen in the include for safec_lib_common.h).

Suggested change
strcpy(p, "This buffer is intentionally leaked.");
(void)strcpy_s(p, 100, "This buffer is intentionally leaked.");

Copilot uses AI. Check for mistakes.
DmErr_t err;
debugLogFile = stderr;

leaky_function();
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

Calling leaky_function in main will cause a memory leak on every program execution. This function serves no purpose and should be removed.

Copilot uses AI. Check for mistakes.
Comment on lines +237 to +245
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.");
// Missing free(p); <-- leak
}
Copy link

Copilot AI Feb 4, 2026

Choose a reason for hiding this comment

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

This entire function appears to be test code for Coverity analysis and should not be included in production code. The PR title explicitly states "DO NOT MERGE", indicating this is intentional test code that should not be merged.

Copilot uses AI. Check for mistakes.
}
strcpy(p, "This buffer is intentionally leaked.");
// Missing free(p); <-- leak
}
Copy link
Contributor

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

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.

2 participants