Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A pointer that points to a freed block of memory is called a stale pointer. Stale pointers are insidious in that dereferecing them does not

A pointer that points to a freed block of memory is called a stale pointer. Stale pointers are insidious in that dereferecing them does not always fail, even though it should. If the pointer was just magically set to NULL upon being freed, then you'd get a seg fault. Your friend writes this wrapper around free to do just this for ints:

void freeint(int *p) {

free(p);

p = null;

}

Try this code out with our own main and see if it crashes on dereferencing a stale pointer. Spoiler, it doesn't. Describe whats wrong and rewrite the code to work as intended. After writing freeint, write a more general stalefree that works for all types but still complies without warnings

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Example. Evaluate 5n+7 lim 7-00 3n-5

Answered: 1 week ago