Skip to content

Commit

Permalink
Fix parser object leak with read_term_from_chars/3
Browse files Browse the repository at this point in the history
  • Loading branch information
infradig committed Apr 24, 2023
1 parent 32afbbd commit 7873af0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/prolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,8 @@ void pl_destroy(prolog *pl)
fclose(str->fp);
}

if (str->p)
parser_destroy(str->p);

parser_destroy(str->p);
str->p = NULL;
map_destroy(str->alias);
free(str->mode);
free(str->filename);
Expand Down
10 changes: 6 additions & 4 deletions src/streams.c
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,8 @@ static bool fn_iso_close_1(query *q)
GET_FIRST_ARG(pstr,stream);
int n = get_stream(q, pstr);
stream *str = &q->pl->streams[n];
parser_destroy(str->p);
str->p = NULL;

if ((str->fp == stdin)
|| (str->fp == stdout)
Expand Down Expand Up @@ -1585,9 +1587,6 @@ static bool fn_iso_close_1(query *q)
map_set(str2->alias, strdup("user_error"), NULL);
}

if (str->p)
parser_destroy(str->p);

if (!str->socket)
del_stream_properties(q, n);

Expand Down Expand Up @@ -4021,8 +4020,10 @@ static bool fn_sys_read_term_from_chars_4(query *q)

char *rest = str->p->srcptr = eat_space(str->p);

if (str->p->error)
if (str->p->error) {
parser_destroy(str->p);
return throw_error(q, q->st.curr_cell, q->st.curr_frame, "syntax_error", str->p->error_desc?str->p->error_desc:"read_term");
}

cell tmp;

Expand Down Expand Up @@ -4155,6 +4156,7 @@ static bool fn_read_term_from_atom_3(query *q)
strcat(src, ".");

bool ok = do_read_term(q, str, p_term, p_term_ctx, p_opts, p_opts_ctx, src);
parser_destroy(str->p);
free(src);
return ok;
}
Expand Down

0 comments on commit 7873af0

Please sign in to comment.