* src/browser.c (do_browser): Plug a memory leak by not copying
a string twice. This fixes Savannah bug #47206.
* src/browser.c (do_browser): Now put things in the proper order.
+ * src/files.c (make_new_buffer), src/nano.c (splice_opennode): Elide
+ the latter function, by handling the two cases (the creation of the
+ first element, and the insertion of a new element) directly.
2016-02-23 Benno Schulenberg <bensberg@justemail.net>
* src/prompt.c (do_statusbar_output, do_statusbar_delete):
* called from open_buffer(). */
void make_new_buffer(void)
{
- /* If there are no entries in openfile, make the first one and
- * move to it. */
if (openfile == NULL) {
openfile = make_new_opennode();
- splice_opennode(openfile, openfile, openfile);
- /* Otherwise, make a new entry for openfile, splice it in after
- * the current entry, and move to it. */
+
+ /* Make the first open file the only element in a circular list. */
+ openfile->prev = openfile;
+ openfile->next = openfile;
} else {
- splice_opennode(openfile, make_new_opennode(), openfile->next);
- openfile = openfile->next;
- /* More than one file open, show Close in help lines. */
+ openfilestruct *newnode = make_new_opennode();
+
+ /* Add the new open file after the current one in the list. */
+ newnode->prev = openfile;
+ newnode->next = openfile->next;
+ openfile->next->prev = newnode;
+ openfile->next = newnode;
+
+ /* Make the new file the current one. */
+ openfile = newnode;
+
+ /* There is more than one file open: show Close in help lines. */
exitfunc->desc = close_tag;
}
return (openfilestruct *)nmalloc(sizeof(openfilestruct));
}
-/* Splice a node into an existing openfilestruct. */
-void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
- openfilestruct *end)
-{
- assert(newnode != NULL && begin != NULL);
-
- newnode->next = end;
- newnode->prev = begin;
- begin->next = newnode;
-
- if (end != NULL)
- end->prev = newnode;
-}
-
/* Unlink a node from the rest of the openfilestruct, and delete it. */
void unlink_opennode(openfilestruct *fileptr)
{
filestruct *top, size_t top_x, filestruct *bot, size_t bot_x);
void copy_from_filestruct(filestruct *somebuffer);
openfilestruct *make_new_opennode(void);
-void splice_opennode(openfilestruct *begin, openfilestruct *newnode,
- openfilestruct *end);
void unlink_opennode(openfilestruct *fileptr);
void delete_opennode(openfilestruct *fileptr);
void print_view_warning(void);