From: wwp <subscript@free.fr>
To: Sameer Maggon <smaggon@dypatil.edu>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: malloc and free
Date: Mon, 20 May 2002 12:06:07 +0200 [thread overview]
Message-ID: <20020520120607.275757c6.subscript@free.fr> (raw)
In-Reply-To: <200205201126.QAA01696@ns1.dypatil.edu>
Hi Sameer,
On Mon, 20 May 2002 16:56:30 +0530 (IST) Sameer Maggon <smaggon@dypatil.edu> wrote:
[snip]
> char *token;
> token = (char *)malloc(256 * sizeof(char));
>
> ...
> ...
> token = strtok(...,"\0");
[snip]
The problem is there, you change "token"'s value, so you
lost the value formerly returned by malloc (this one has
to be free()'ed) because strtok returns a pointer to the next
token IIRC. Then, the "token" you attempt to free is not
the good one.
For instance, if I didn't miss anything:
char *token, *buffer;
buffer = (char *)malloc(256 * sizeof(char));
token = buffer;
token = strtok(...,"\0");
..
free(buffer);
Regards,
--
wwp
next prev parent reply other threads:[~2002-05-20 10:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-05-20 11:26 malloc and free Sameer Maggon
2002-05-20 10:06 ` wwp [this message]
2002-05-20 18:16 ` Andrew Edmondson
-- strict thread matches above, loose matches on Subject: below --
2004-12-24 18:39 Ankit Jain
2004-12-24 18:53 ` Ray Olszewski
2004-12-25 3:16 ` Jagadeesh Bhaskar P
2004-12-24 18:39 Ankit Jain
2004-12-24 18:52 ` Eric Bambach
2002-05-20 9:55 Alvarez Alberto-AALVARB1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20020520120607.275757c6.subscript@free.fr \
--to=subscript@free.fr \
--cc=linux-c-programming@vger.kernel.org \
--cc=smaggon@dypatil.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.