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

  • SEARCH
  • Home
  • 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 6715417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:36:43+00:00 2026-05-26T08:36:43+00:00

Can anyone give out some example code which will make malloc signal an sigsegv?

  • 0

Can anyone give out some example code which will make malloc signal an sigsegv?
Googled that, heap corruption may lead to an sigsegv in malloc, but I can’t understand that.

Thanks a lot.

  • 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-05-26T08:36:44+00:00Added an answer on May 26, 2026 at 8:36 am

    There’s a decent chance this will cause problems, though it might be free() rather than malloc() that gives you the SIGSEGV.

     void *vp = malloc(1024);
     memset((char *)vp - 32, 0, 1024);
     free(vp);
    

    You might get the crash in malloc() with:

     enum { SZ_ALLOC = 1024, SZ_PREFIX = 32, SZ_SUFFIX = 32, SET_BYTE = '\0' };
    
     void *v1 = malloc(SZ_ALLOC);
     free(v1);
     memset((char *)v1 - SZ_PREFIX, SET_BYTE, SZ_ALLOC + SZ_PREFIX + SZ_SUFFIX);
     void *v2 = malloc(SZ_ALLOC);
    

    This overwrites 32 bytes before and after the allocated memory, which is likely to corrupt any control information if it is stored contiguously will the allocated memory (which is usually the case). Using zeroes maximizes the chance that you’ll get a null pointer access. You could choose an alternative value to write over the data which might means that sizes appear larger than zero (where zero sizes might protect you from memory access).

    Of course, this is all completely undefined behaviour; you might get the crash in memset(), or you might not get a crash at all.

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

Sidebar

Related Questions

I'd like to try out OpenGL programming in Scheme. Can anyone give a recommendation
Can anyone give me pointers to good books or web sites that teach how
Can anyone give a concise set of real-world considerations that would drive the choice
Can anyone give me an example of how I can consume the following web
Can anyone give me an example (or point me in the right direction) on
Can anyone give me a complete list of string manipulation function in Microsoft SQL
Can anyone give me details of runtime error 3734 in Access vba. For reference
Can anyone give me a scenario where they think busy cursors are justified? I
Can anyone give me an idea how can we show or embed a YouTube
Can anyone give an idea of how should I implement undo/redo of cutting/copying/pasting of

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.