Skip to content

Commit

Permalink
Check for nullptr return from malloc called from AllocateBuffers in L…
Browse files Browse the repository at this point in the history
…iteral.

PiperOrigin-RevId: 718967904
  • Loading branch information
Google-ML-Automation committed Feb 3, 2025
1 parent 3905a2c commit 34d2633
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions xla/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ cc_library(
"@com_google_absl//absl/base:core_headers",
"@com_google_absl//absl/container:inlined_vector",
"@com_google_absl//absl/functional:function_ref",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/status",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:str_format",
Expand Down
7 changes: 5 additions & 2 deletions xla/literal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ limitations under the License.
#include "absl/base/casts.h"
#include "absl/container/inlined_vector.h"
#include "absl/functional/function_ref.h"
#include "absl/log/check.h"
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
Expand Down Expand Up @@ -627,8 +628,10 @@ void LiteralBase::Piece::AllocateBuffers() {
if (bytes > kMaxInlinedBytes) {
CHECK_EQ(buffer(), nullptr);
rep_.emplace<DenseRep>();
set_buffer(
static_cast<char*>(tsl::port::AlignedMalloc(bytes, kMinimumAlignment)));
char* buffer =
static_cast<char*>(tsl::port::AlignedMalloc(bytes, kMinimumAlignment));
CHECK(buffer != nullptr) << "Failed to allocate buffer for Literal";
set_buffer(buffer);
} else {
rep_.emplace<DenseInlinedRep>();
}
Expand Down

0 comments on commit 34d2633

Please sign in to comment.