Skip to content

Comments

leaky function coverity testing -- DO NOT MERGE#21

Closed
SanthoshGujulvajagadeesh wants to merge 1 commit intodevelopfrom
raise_pr_coverity_testing
Closed

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

Conversation

@SanthoshGujulvajagadeesh

No description provided.

@SanthoshGujulvajagadeesh SanthoshGujulvajagadeesh marked this pull request as ready for review February 4, 2026 07:20
Copilot AI review requested due to automatic review settings February 4, 2026 07:20
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 pull request introduces an intentionally defective function for testing Coverity static analysis capabilities. The PR adds a function with deliberate memory management and security issues to verify that the static analysis tool can detect these problems.

Changes:

  • Added leaky_function() with intentional memory leak and unsafe string operation
  • Added call to leaky_function() in the main function

💡 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: 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.

Copilot uses AI. Check for mistakes.
Comment on lines +239 to +243
if (!p) {
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.

Use of strcpy is unsafe and can lead to buffer overflow vulnerabilities. Consider using strncpy or snprintf with explicit bounds checking to ensure the string does not exceed the allocated buffer size.

Suggested change
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 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 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.

Copilot uses AI. Check for mistakes.
Comment on lines +260 to +261
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 introduces a memory leak at program startup. This call should be removed as it serves no functional purpose and wastes system resources.

Suggested change
leaky_function();

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

@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants