add checks before freeing memory

This commit is contained in:
Chris Cromer 2021-07-06 15:00:57 -04:00
parent 4a2a9eb3b8
commit 9d0615fbcd

View File

@ -84,8 +84,14 @@ void print_input_line() {
char *hostname = get_hostname(); char *hostname = get_hostname();
char *cwd = get_working_directory(); char *cwd = get_working_directory();
printf(BRIGHT_GREEN "%s" RESET BRIGHT_MAGENTA "@" RESET BRIGHT_RED "%s" RESET BRIGHT_MAGENTA ":" RESET BRIGHT_BLUE "%s" RESET BRIGHT_MAGENTA "$ " RESET, username, hostname, cwd); printf(BRIGHT_GREEN "%s" RESET BRIGHT_MAGENTA "@" RESET BRIGHT_RED "%s" RESET BRIGHT_MAGENTA ":" RESET BRIGHT_BLUE "%s" RESET BRIGHT_MAGENTA "$ " RESET, username, hostname, cwd);
if (hostname != NULL) {
free(hostname); free(hostname);
hostname = NULL;
}
if (cwd != NULL) {
free(cwd); free(cwd);
cwd = NULL;
}
} }
/** /**