From: Benno Schulenberg <bensberg@justemail.net>
Date: Sun, 14 Jun 2015 19:14:41 +0000 (+0000)
Subject: Not checking for non-NULL before freeing a variable, as it's unnecessary.
X-Git-Tag: v2.4.2~28
X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=c32a58a826a40c1b90a61ee5ab68ced25cb190f2;p=nano.git

Not checking for non-NULL before freeing a variable, as it's unnecessary.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5249 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---

diff --git a/ChangeLog b/ChangeLog
index d2ea86b1..ed47f608 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,6 +7,7 @@
 	* src/winio.c (edit_draw): When the whole line has been coloured,
 	don't bother looking for any more starts.  This prevents some lines
 	from being erroneously marked as CENDAFTER instead of CWHOLELINE.
+	* src/*.c: Don't check for non-NULL before freeing; it's unneeded.
 
 2015-06-11  Benno Schulenberg  <bensberg@justemail.net>
 	* src/winio.c (get_key_buffer): Add some debugging code to make it
diff --git a/src/browser.c b/src/browser.c
index ad59baf8..98beef1e 100644
--- a/src/browser.c
+++ b/src/browser.c
@@ -405,8 +405,7 @@ char *do_browse_from(const char *inpath)
 
     /* If we can't open the path, get out. */
     if (dir == NULL) {
-	if (path != NULL)
-	    free(path);
+	free(path);
 	beep();
 	return NULL;
     }
diff --git a/src/color.c b/src/color.c
index cae9c2a8..3c33aa7e 100644
--- a/src/color.c
+++ b/src/color.c
@@ -70,10 +70,8 @@ void set_colorpairs(void)
 		interface_color_pair[i].pairnum = A_NORMAL;
 	}
 
-	if (specified_color_combo[i] != NULL) {
-	    free(specified_color_combo[i]);
-	    specified_color_combo[i] = NULL;
-	}
+	free(specified_color_combo[i]);
+	specified_color_combo[i] = NULL;
     }
 
     for (; this_syntax != NULL; this_syntax = this_syntax->next) {
diff --git a/src/files.c b/src/files.c
index 44550185..3b579787 100644
--- a/src/files.c
+++ b/src/files.c
@@ -830,10 +830,8 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw
 	    /* Move fileptr back one line and blow away the old fileptr,
 	     * since its text has been saved. */
 	    fileptr = fileptr->prev;
-	    if (fileptr != NULL) {
-		if (fileptr->next != NULL)
-		    free(fileptr->next);
-	    }
+	    if (fileptr != NULL)
+		free(fileptr->next);
 	}
 
 	/* Attach the line at current after the line at fileptr. */
@@ -1454,8 +1452,7 @@ char *get_full_path(const char *origpath)
     }
 
     /* Free d_there_file, since we're done using it. */
-    if (d_there_file != NULL)
-	free(d_there_file);
+    free(d_there_file);
 
     return d_there;
 }
@@ -2177,8 +2174,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
 
   cleanup_and_exit:
     free(realname);
-    if (tempname != NULL)
-	free(tempname);
+    free(tempname);
 
     return retval;
 }
@@ -2401,10 +2397,8 @@ bool do_writeout(bool exiting)
 		 * string's real length. */
 		unsunder(answer, answer_len);
 
-		if (full_filename != NULL)
-		    free(full_filename);
-		if (full_answer != NULL)
-		    free(full_answer);
+		free(full_filename);
+		free(full_answer);
 
 		if (do_warning) {
 		    /* If we're using restricted mode, we aren't allowed
diff --git a/src/global.c b/src/global.c
index 614e46d6..f1477308 100644
--- a/src/global.c
+++ b/src/global.c
@@ -1580,32 +1580,25 @@ void thanks_for_all_the_fish(void)
     delwin(bottomwin);
 
 #ifndef DISABLE_JUSTIFY
-    if (quotestr != NULL)
-	free(quotestr);
+    free(quotestr);
 #ifdef HAVE_REGEX_H
     regfree(&quotereg);
-    if (quoteerr != NULL)
-	free(quoteerr);
+    free(quoteerr);
 #endif
 #endif
 #ifndef NANO_TINY
-    if (backup_dir != NULL)
-	free(backup_dir);
+    free(backup_dir);
 #endif
 #ifndef DISABLE_OPERATINGDIR
-    if (operating_dir != NULL)
-	free(operating_dir);
-    if (full_operating_dir != NULL)
-	free(full_operating_dir);
+    free(operating_dir);
+    free(full_operating_dir);
 #endif
+    free(answer);
     free(last_search);
     free(last_replace);
 #ifndef DISABLE_SPELLER
-    if (alt_speller != NULL)
-	free(alt_speller);
+    free(alt_speller);
 #endif
-    if (answer != NULL)
-	free(answer);
     if (cutbuffer != NULL)
 	free_filestruct(cutbuffer);
 #ifndef DISABLE_JUSTIFY
@@ -1616,8 +1609,7 @@ void thanks_for_all_the_fish(void)
     if (openfile != NULL)
 	free_openfilestruct(openfile);
 #ifndef DISABLE_COLOR
-    if (syntaxstr != NULL)
-	free(syntaxstr);
+    free(syntaxstr);
     while (syntaxes != NULL) {
 	syntaxtype *bill = syntaxes;
 
@@ -1692,8 +1684,7 @@ void thanks_for_all_the_fish(void)
 	free(s);
     }
 #ifndef DISABLE_NANORC
-    if (homedir != NULL)
-	free(homedir);
+    free(homedir);
 #endif
 }
 
diff --git a/src/help.c b/src/help.c
index 2ad5bce6..a3c5477f 100644
--- a/src/help.c
+++ b/src/help.c
@@ -387,8 +387,7 @@ void help_init(void)
 
     /* help_text has been freed and set to NULL unless the user resized
      * while in the help screen. */
-    if (help_text != NULL)
-	free(help_text);
+    free(help_text);
 
     /* Allocate space for the help text. */
     help_text = charalloc(allocsize + 1);
diff --git a/src/nano.c b/src/nano.c
index 6cb9127d..e5540a06 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -123,14 +123,10 @@ void delete_node(filestruct *fileptr)
 {
     assert(fileptr != NULL && fileptr->data != NULL);
 
-    if (fileptr->data != NULL)
-	free(fileptr->data);
-
+    free(fileptr->data);
 #ifndef DISABLE_COLOR
-    if (fileptr->multidata)
-	free(fileptr->multidata);
+    free(fileptr->multidata);
 #endif
-
     free(fileptr);
 }
 
@@ -572,10 +568,8 @@ void delete_opennode(openfilestruct *fileptr)
     free(fileptr->filename);
     free_filestruct(fileptr->fileage);
 #ifndef NANO_TINY
-    if (fileptr->current_stat != NULL)
-	free(fileptr->current_stat);
+    free(fileptr->current_stat);
 #endif
-
     free(fileptr);
 }
 
diff --git a/src/prompt.c b/src/prompt.c
index 61c4347f..2cd5b7ab 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -918,8 +918,7 @@ functionptrtype get_prompt_string(int *actual, bool allow_tabs,
     if (history_list != NULL) {
 	history_reset(*history_list);
 
-	if (magichistory != NULL)
-	    free(magichistory);
+	free(magichistory);
     }
 #endif
 
@@ -977,8 +976,7 @@ int do_prompt(bool allow_tabs,
 
     /* prompt has been freed and set to NULL unless the user resized
      * while at the statusbar prompt. */
-    if (prompt != NULL)
-	free(prompt);
+    free(prompt);
 
     prompt = charalloc(((COLS - 4) * mb_cur_max()) + 1);
 
diff --git a/src/rcfile.c b/src/rcfile.c
index 581456de..abf9c07c 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -985,8 +985,7 @@ void parse_linter(char *ptr)
 	return;
     }
 
-    if (endsyntax->linter != NULL)
-	free(endsyntax->linter);
+    free(endsyntax->linter);
 
     /* Let them unset the linter by using "". */
     if (!strcmp(ptr, "\"\""))
@@ -1012,8 +1011,7 @@ void parse_formatter(char *ptr)
 	return;
     }
 
-    if (endsyntax->formatter != NULL)
-	free(endsyntax->formatter);
+    free(endsyntax->formatter);
 
     /* Let them unset the formatter by using "". */
     if (!strcmp(ptr, "\"\""))
diff --git a/src/text.c b/src/text.c
index 76524faa..f3637f86 100644
--- a/src/text.c
+++ b/src/text.c
@@ -885,8 +885,7 @@ void add_undo(undo_type current_action)
     while (fs->undotop != NULL && fs->undotop != fs->current_undo) {
 	undo *u2 = fs->undotop;
 	fs->undotop = fs->undotop->next;
-	if (u2->strdata != NULL)
-	    free(u2->strdata);
+	free(u2->strdata);
 	if (u2->cutbuffer)
 	    free_filestruct(u2->cutbuffer);
 	free(u2);