add checks before freeing memory
This commit is contained in:
parent
4a2a9eb3b8
commit
9d0615fbcd
@ -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);
|
||||||
free(hostname);
|
if (hostname != NULL) {
|
||||||
free(cwd);
|
free(hostname);
|
||||||
|
hostname = NULL;
|
||||||
|
}
|
||||||
|
if (cwd != NULL) {
|
||||||
|
free(cwd);
|
||||||
|
cwd = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user