Skip to content

Commit

Permalink
Don't allocate args when instruction parsing fails
Browse files Browse the repository at this point in the history
.. 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.
  • Loading branch information
jepler committed Mar 17, 2018
1 parent 523a88a commit 7cec815
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libtvm/tvm_parser.c
Expand Up @@ -189,10 +189,13 @@ int tvm_parse_program(
int opcode = tvm_parse_instr(
vm, tokens[line_idx], &instr_place);

if (opcode == -1)
continue;

int **args = tvm_parse_args(
vm, tokens[line_idx], &instr_place);

if (opcode == -1 || !args)
if (!args)
continue;

void *newptr;
Expand Down

0 comments on commit 7cec815

Please sign in to comment.