delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2013/01/14/15:52:57

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-3.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,KHOP_RCVD_TRUST,KHOP_THREADED,RCVD_IN_DNSWL_LOW,RCVD_IN_HOSTKARMA_YE
X-Spam-Check-By: sourceware.org
MIME-Version: 1.0
In-Reply-To: <1358135756673-95377.post@n5.nabble.com>
References: <1358135756673-95377 DOT post AT n5 DOT nabble DOT com>
Date: Sun, 13 Jan 2013 20:52:30 -0800
Message-ID: <CAPF-yObDjWtx5bQEmCk1nCzoo-razSns+yvq2VXsnv2d+PYX_w@mail.gmail.com>
Subject: Re: Using the free(*ptr) routine and getting an exception, "Exception: STATUS_ACCESS_VIOLATION"
From: Dan Kegel <dank AT kegel DOT com>
To: cygwin AT cygwin DOT com
Cc: yzfury AT gmail DOT com
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Unsubscribe: <mailto:cygwin-unsubscribe-archive-cygwin=delorie DOT com AT cygwin DOT com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

On Sun, Jan 13, 2013 at 7:55 PM, YZFury <yzfury AT gmail DOT 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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019