apache/hadoop · error

malloc(%d) failed

Error message

malloc(%d) failed

What it means

Error "malloc(%d) failed " thrown in apache/hadoop.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs-tests/test_libhdfs_zerocopy.c:52

#define TO_STR(X) TO_STR_HELPER(X)

#define TEST_FILE_NAME_LENGTH 128
#define TEST_ZEROCOPY_FULL_BLOCK_SIZE 4096
#define TEST_ZEROCOPY_LAST_BLOCK_SIZE 3215
#define TEST_ZEROCOPY_NUM_BLOCKS 6
#define SMALL_READ_LEN 16
#define TEST_ZEROCOPY_FILE_LEN \
  (((TEST_ZEROCOPY_NUM_BLOCKS - 1) * TEST_ZEROCOPY_FULL_BLOCK_SIZE) + \
    TEST_ZEROCOPY_LAST_BLOCK_SIZE)

#define ZC_BUF_LEN 32768

static uint8_t *getZeroCopyBlockData(int blockIdx)
{
    uint8_t *buf = malloc(TEST_ZEROCOPY_FULL_BLOCK_SIZE);
    int i;
    if (!buf) {
        fprintf(stderr, "malloc(%d) failed\n", TEST_ZEROCOPY_FULL_BLOCK_SIZE);
        exit(1);
    }
    for (i = 0; i < TEST_ZEROCOPY_FULL_BLOCK_SIZE; i++) {
      buf[i] = (uint8_t)(blockIdx + (i % 17));
    }
    return buf;
}

static int getZeroCopyBlockLen(int blockIdx)
{
    if (blockIdx >= TEST_ZEROCOPY_NUM_BLOCKS) {
        return 0;
    } else if (blockIdx == (TEST_ZEROCOPY_NUM_BLOCKS - 1)) {
        return TEST_ZEROCOPY_LAST_BLOCK_SIZE;
    } else {
        return TEST_ZEROCOPY_FULL_BLOCK_SIZE;
    }
}

View on GitHub (pinned to 2add963021)

Solutions

  1. Reduce the requested allocation (TEST_ZEROCOPY_PORTION / buffer size) to fit available memory.
  2. Run on a host with more free RAM or raise the process memory limit (ulimit -v).
  3. Check for a bug passing an excessively large size to malloc in the test arguments.

When it happens

Trigger: malloc returned NULL when test_libhdfs_zerocopy allocated its read buffer.

Common situations: Memory exhaustion on the test host, or an unrealistically large buffer length configured for the zerocopy test.


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/fae12bcb188e84da. Report an issue: GitHub.