<p></p>
<p><b>@elextr</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/geany/geany/pull/2769#discussion_r603641348">plugins/saveactions.c</a>:</p>
<pre style='color:#555'>>                      SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL));
 
+               /* create new file */
+               fd = g_mkstemp(new_filename);
+               if (fd == -1)
+               {
+                       gchar *message = g_strdup_printf(
+                               _("Instant Save filename could not be generated (%s)."), g_strerror(errno));
+                       ui_set_statusbar(TRUE, "%s", message);
+                       g_warning("%s", message);
+                       g_free(message);
+                       return;
</pre>
<p>leaks <code>new_filename</code></p>

<hr>

<p>In <a href="https://github.com/geany/geany/pull/2769#discussion_r603642623">plugins/saveactions.c</a>:</p>
<pre style='color:#555'>>              if (ft == NULL || ft->id == GEANY_FILETYPES_NONE)
                        /* ft is NULL when a new file without template was opened, so use the
                         * configured default file type */
                        ft = filetypes_lookup_by_name(instantsave_default_ft);
 
-               if (ft != NULL)
-                       /* add the filetype's default extension to the new filename */
+               /* construct filename */
+               directory = !EMPTY(instantsave_target_dir) ? instantsave_target_dir : g_get_tmp_dir();
+               new_filename = g_build_filename(directory, "gis_XXXXXX", NULL);
+               if (ft != NULL && !EMPTY(ft->extension))
                        SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL));
</pre>
<p><code>ft == NULL</code> means <code>doc->file_type</code> is NULL, but its not set before being dereferenced at <strong>here</strong> below</p>

<hr>

<p>In <a href="https://github.com/geany/geany/pull/2769#discussion_r603642686">plugins/saveactions.c</a>:</p>
<pre style='color:#555'>>                      SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL));
 
+               /* create new file */
+               fd = g_mkstemp(new_filename);
+               if (fd == -1)
+               {
+                       gchar *message = g_strdup_printf(
+                               _("Instant Save filename could not be generated (%s)."), g_strerror(errno));
+                       ui_set_statusbar(TRUE, "%s", message);
+                       g_warning("%s", message);
+                       g_free(message);
+                       return;
+               }
+
+               close(fd); /* close the returned file descriptor as we only need the filename */
+
                doc->file_name = new_filename;
 
                if (doc->file_type->id == GEANY_FILETYPES_NONE)
</pre>
<p><strong>here</strong></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany/pull/2769#pullrequestreview-623684122">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAIOWJ3NRG7HITSCWIKHDD3TGD67DANCNFSM4ZSS3CGA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AAIOWJ622V547W5HBZ7NOOTTGD67DA5CNFSM4ZSS3CGKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOEUWKUGQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/geany/geany/pull/2769#pullrequestreview-623684122",
"url": "https://github.com/geany/geany/pull/2769#pullrequestreview-623684122",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>