Index: contrib/binutils/libiberty/make-relative-prefix.c =================================================================== --- contrib/binutils/libiberty/make-relative-prefix.c +++ contrib/binutils/libiberty/make-relative-prefix.c @@ -299,10 +299,16 @@ full_progname = strdup(progname); prog_dirs = split_directories (full_progname, &prog_num); - bin_dirs = split_directories (bin_prefix, &bin_num); + if (prog_dirs == NULL) { + free (full_progname); + return NULL; + } free (full_progname); - if (bin_dirs == NULL || prog_dirs == NULL) + bin_dirs = split_directories (bin_prefix, &bin_num); + if (bin_dirs == NULL) { + free_split_directories(prog_dirs); return NULL; + } /* Remove the program name from comparison of directory names. */ prog_num--; @@ -364,8 +370,12 @@ needed_len += 1; /* Trailing NUL. */ ret = (char *) malloc (needed_len); - if (ret == NULL) + if (ret == NULL) { + free_split_directories (prog_dirs); + free_split_directories (bin_dirs); + free_split_directories (prefix_dirs); return NULL; + } /* Build up the pathnames in argv[0]. */ *ret = '\0';