CAS-002 · Question #820
The following has been discovered in an internally developed application: Error - Memory allocated but not freed: char myBuffer = malloc(BUFFER_SIZE); if (myBuffer != NULL) { myBuffer =…
The correct answer is A. Static code analysis C. Manual code review. The code allocates heap memory with malloc() but never calls free() before exiting, a memory leak that is detectable only by examining the source code directly or with automated source analysis tools.
Question
The following has been discovered in an internally developed application:
Error - Memory allocated but not freed:
char *myBuffer = malloc(BUFFER_SIZE); if (myBuffer != NULL) { *myBuffer = STRING_WELCOME_MESSAGE; printf("Welcome to: %s\n", myBuffer); } exit(0); Which of the following security assessment methods are likely to reveal this security weakness? (Select TWO).
Options
- AStatic code analysis
- BMemory dumping
- CManual code review
- DApplication sandboxing
- EPenetration testing
- FBlack box testing
How the community answered
(30 responses)- A73% (22)
- B3% (1)
- D7% (2)
- E3% (1)
- F13% (4)
Why each option
The code allocates heap memory with malloc() but never calls free() before exiting, a memory leak that is detectable only by examining the source code directly or with automated source analysis tools.
Static code analysis tools parse source code without executing it and apply rules to flag CWE-401 (missing release of memory), directly identifying that free(myBuffer) is never called before exit(0).
Memory dumping captures a runtime snapshot of memory contents but does not expose source-level allocation patterns or indicate which code path failed to release the buffer.
Manual code review allows a human analyst to trace the execution path and observe that once the printf completes the pointer is never passed to free(), confirming the memory is leaked on every invocation.
Application sandboxing isolates a process for behavioral containment and threat analysis but does not perform source code inspection and would not surface the absent free() call.
Penetration testing attempts to exploit known vulnerability classes from an attacker perspective and is not designed to audit internal memory management correctness in application source code.
Black box testing evaluates application behavior through inputs and outputs without source access, making it unable to detect or locate the specific missing deallocation statement.
Concept tested: Memory leak detection via static and manual source analysis
Source: https://cwe.mitre.org/data/definitions/401.html
Topics
Community Discussion
No community discussion yet for this question.