This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Using the free(*ptr) routine and getting an exception, "Exception: STATUS_ACCESS_VIOLATION"


On Sun, Jan 13, 2013 at 7:55 PM, YZFury <yzfury@gmail.com> wrote:
> int *ptr = malloc(sizeof(*ptr));
>         int x = 87;
>         ptr = &x;
>         printf("%d", *ptr);
>         free(ptr);//it goes wrong here

As you probably know, you can't call free() on a pointer
that didn't come from malloc().  ptr's first value came from malloc,
but you overwrote that with
   ptr = &x;
Perhaps you meant
   *ptr = x;
So you're a level of indirection off.
- Dan

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]