diff --git a/ShellPkg/Library/UefiSortLib/UefiSortLib.c b/ShellPkg/Library/UefiSortLib/UefiSortLib.c index 73ee7830fc..9cff46d4e6 100644 --- a/ShellPkg/Library/UefiSortLib/UefiSortLib.c +++ b/ShellPkg/Library/UefiSortLib/UefiSortLib.c @@ -13,6 +13,7 @@ **/ #include +#include #include #include @@ -251,13 +252,19 @@ DevicePathCompare ( FALSE, FALSE); - RetVal = mUnicodeCollation->StriColl( - mUnicodeCollation, - TextPath1, - TextPath2); + if (TextPath1 == NULL) { + RetVal = -1; + } else if (TextPath2 == NULL) { + RetVal = 1; + } else { + RetVal = mUnicodeCollation->StriColl( + mUnicodeCollation, + TextPath1, + TextPath2); + } - FreePool(TextPath1); - FreePool(TextPath2); + SHELL_FREE_NON_NULL(TextPath1); + SHELL_FREE_NON_NULL(TextPath2); return (RetVal); }