Skip to content

Commit b4510d1

Browse files
pratikasharigcbot
authored andcommitted
Fix memory leak
OutputAsmPath string value was being duplicated using strdup() and it was never deallocated. Fixed by allocating memory in CISA_IR_Builder's arena allocator.
1 parent a2021ff commit b4510d1

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

visa/BuildCISAIRImpl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2482,7 +2482,13 @@ bool CISA_IR_Builder::CISA_attr_directive(const char *input_name,
24822482
}
24832483
input_name = "OutputAsmPath"; // normalize to new name
24842484

2485-
char *asmFileName = strdup(input_var);
2485+
// OutputAsmPath attribute value is copied to an arena allocated buffer.
2486+
// So we don't need to explicitly deallocate the buffer.
2487+
const unsigned int maxStrSize = 1024;
2488+
unsigned int strLength = strnlen_s(input_var, maxStrSize);
2489+
unsigned int allocSize = strLength + 1;
2490+
char *asmFileName = (char *)(m_mem.alloc(allocSize));
2491+
strncpy_s(asmFileName, allocSize, input_var, strLength);
24862492
char *pos = strstr(asmFileName, ".asm");
24872493
if (pos != NULL) {
24882494
*pos = '\0';

0 commit comments

Comments
 (0)