patch 8.1.1946: memory error when profiling a function without a script ID

Problem:    Memory error when profiling a function without a script ID.
Solution:   Check for missing script ID.  (closes #4877)
This commit is contained in:
Bram Moolenaar
2019-08-30 18:37:26 +02:00
parent 9e67b6a6a1
commit 163588005d
3 changed files with 37 additions and 5 deletions

View File

@ -690,13 +690,16 @@ func_dump_profile(FILE *fd)
fprintf(fd, "FUNCTION <SNR>%s()\n", fp->uf_name + 3);
else
fprintf(fd, "FUNCTION %s()\n", fp->uf_name);
p = home_replace_save(NULL,
get_scriptname(fp->uf_script_ctx.sc_sid));
if (p != NULL)
if (fp->uf_script_ctx.sc_sid > 0)
{
fprintf(fd, " Defined: %s line %ld\n",
p = home_replace_save(NULL,
get_scriptname(fp->uf_script_ctx.sc_sid));
if (p != NULL)
{
fprintf(fd, " Defined: %s line %ld\n",
p, (long)fp->uf_script_ctx.sc_lnum);
vim_free(p);
vim_free(p);
}
}
if (fp->uf_tm_count == 1)
fprintf(fd, "Called 1 time\n");