| delorie.com/archives/browse.cgi | search |
| X-Recipient: | archive-cygwin AT delorie DOT com |
| X-SWARE-Spam-Status: | No, hits=3.2 required=5.0 tests=AWL,BAYES_40,DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,KHOP_THREADED,NML_ADSP_CUSTOM_MED,SPF_NEUTRAL,URI_HEX |
| X-Spam-Check-By: | sourceware.org |
| Date: | Sun, 13 Jan 2013 21:11:44 -0800 (PST) |
| From: | YZFury <yzfury AT gmail DOT com> |
| To: | cygwin AT cygwin DOT com |
| Message-ID: | <3e6368c8-5f18-496c-b677-cf499369b3be@email.android.com> |
| In-Reply-To: | <CAPF-yObDjWtx5bQEmCk1nCzoo-razSns+yvq2VXsnv2d+PYX_w@mail.gmail.com> |
| References: | <1358135756673-95377 DOT post AT n5 DOT nabble DOT com> <CAPF-yObDjWtx5bQEmCk1nCzoo-razSns+yvq2VXsnv2d+PYX_w AT mail DOT gmail DOT com> |
| Subject: | Re: Using the free(*ptr) routine and getting an exception, "Exception: STATUS_ACCESS_VIOLATION" |
| MIME-Version: | 1.0 |
| 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 |
Whoops. I was making the pointer point to x instead of putting x's value in the memory that was just allocated. Now i understand that. Really sorry for a stupid syntax error question on my part. thanks for the quick reply though :). Like I said basically new to C.
Sent from my Kindle Fire
_____________________________________________
From: "Dan Kegel-2 [via Cygwin]" <ml-node+s1069669n95381h52 AT n5 DOT nabble DOT com>
Sent: Sun Jan 13 23:52:50 EST 2013
To: YZFury <yzfury AT gmail DOT com>
Subject: Re: Using the free(*ptr) routine and getting an exception, "Exception: STATUS_ACCESS_VIOLATION"
On Sun, Jan 13, 2013 at 7:55 PM, YZFury <[hidden email]> 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
_____________________________________________
If you reply to this email, your message will be added to the discussion below:
http://cygwin.1069669.n5.nabble.com/Using-the-free-ptr-routine-and-getting-an-exception-Exception-STATUS-ACCESS-VIOLATION-tp95377p95381.html
To unsubscribe from Using the free(*ptr) routine and getting an exception, "Exception: STATUS_ACCESS_VIOLATION", click here.
NAML
--
View this message in context: http://cygwin.1069669.n5.nabble.com/Using-the-free-ptr-routine-and-getting-an-exception-Exception-STATUS-ACCESS-VIOLATION-tp95377p95382.html
Sent from the Cygwin list mailing list archive at Nabble.com.
--
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
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |