Skip to content

Commit 7cec815

Browse files
committed
Don't allocate args when instruction parsing fails
.. it looks like (opcode == -1) should maybe lead to an error return rather than a continue, but in any case we need to avoid leaking 'args' in this situation. .. the previous arrangement lead to compiler diagnostics when building with 'scan-build make', such as: libtvm/tvm_parser.c:186:39: warning: Potential leak of memory pointed to by 'args' for (line_idx = 0; tokens[line_idx]; line_idx++) { ^~~~~~~~ 1 warning generated.
1 parent 523a88a commit 7cec815

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

libtvm/tvm_parser.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,13 @@ int tvm_parse_program(
189189
int opcode = tvm_parse_instr(
190190
vm, tokens[line_idx], &instr_place);
191191

192+
if (opcode == -1)
193+
continue;
194+
192195
int **args = tvm_parse_args(
193196
vm, tokens[line_idx], &instr_place);
194197

195-
if (opcode == -1 || !args)
198+
if (!args)
196199
continue;
197200

198201
void *newptr;

0 commit comments

Comments
 (0)