Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > malloc() for struct member

Thread Tools

malloc() for struct member

Posts: n/a
After you free the memory, set the member variable to NULL and see if that
changes anything.

When you start getting weird errors/crashes, it's usually worthwhile to look
for buffer overruns, freeing memory that has already been freed, and things
like that.

DataGet & PocketLog
Data Collectors

"googler" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)
> > What prompted the question?

> A code like the one I gave resulted in a crash. That's why I posted the
> question. My main point was if allocating and freeing memory is OK when
> done on a struct member (I knew it's OK, but the above crash made me a
> bit confused).
> I presume it's a compilation problem since the release build works and
> the crash happens for debug build (which is weird since it is usually
> the other way round).

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
pointer to a member of a struct which is in turn a member of an arrayof structs pete142 C Programming 5 01-23-2008 01:11 AM
Using an instance of a struct as a member of that struct dutchgoldtony C Programming 15 11-16-2005 11:24 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
How would I use qsort to sort a struct with a char* member and a long member - I want to sort in order of the long member Angus Comber C Programming 7 02-05-2004 06:41 PM