Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8233657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:12:17+00:00 2026-06-07T18:12:17+00:00

My program is in C and I’m compiling with gcc. I’m reading in a

  • 0

My program is in C and I’m compiling with gcc. I’m reading in a file, and storing the contents of the file into a buffer. To do that I need the buffer to be as large as the file. I’m using malloc() to allocate memory for the buffer. Unfortunately, I ran into a file that’s 277MB. Is that too much for the heap? I’m getting a seg fault at run time, but no more information than that. It’s worked for files as large as 160 MB, but this single outlier of a 277MB file is breaking it.

EDIT: valgrind gives me

@0xC0000022L valgrind gives me

==6380== Warning: set address range perms: large range [0x8851028, 0x190e6102) (undefined)
==6380== Warning: set address range perms: large range [0x8851028, 0x190e6028) (defined)
==6380== Warning: set address range perms: large range [0x190e7028, 0x2997c108) (undefined)
==6380== Warning: set address range perms: large range [0x190e7028, 0x2997c028) (defined)
==6380== Warning: silly arg (-1737565464) to malloc()
==6380== Invalid write of size 4
==6380==    at 0x8048A49: main (newanalyze.c:85)
==6380==  Address 0x4a00 is not stack'd, malloc'd or (recently) free'd
==6380==
==6380==
==6380== Process terminating with default action of signal 11 (SIGSEGV)
==6380==  Access not within mapped region at address 0x4A00
==6380==    at 0x8048A49: main (newanalyze.c:85)

but at line 85 is just a small variable that shouldn’t be affected by the size of the file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:12:18+00:00Added an answer on June 7, 2026 at 6:12 pm

    Unfortunately I can’t give you a solid “why,” but mmap2, which appearas to be what malloc is calling on your system, simply reports it’s out of memory. Malloc will, in this case, return NULL cause a segfault.

    munmap(0xb7706000, 4096)                = 0
    mmap2(NULL, 2557403136, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = -1  ENOMEM (Cannot allocate memory)
    

    As a counter example, I have a toy program that succeeds with:

    mmap(NULL, 283652096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f2d00994000
    

    I would check the memory available on the system or that the program is using. Maybe it’s leaking memory badly?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The program that I am working on takes a file and parses it line
My program receives an executable binary file through a TCP socket. I need to
Program that calculates and shows the value of (2 to the 10th power) This
NOTE: program in java, server uses php, and mysql...file is .log or .txt file
Program I'm making has a simple configuration file looking something like this. @overlays =
My program is a game that uses RMI to allow users to connect to
Program : List all C files in the current folder using execlp() system call:
My program needs to receive strings through the serialport. Problem is that the program
/*Program to merge to arrays using pointers in descending order, when the first array
Program A, is a c program that endlessly, receives input in stdin, process it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.