Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7013207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:21:24+00:00 2026-05-27T22:21:24+00:00

I have a structure which contains some elements, i free the memory of this

  • 0

I have a structure which contains some elements, i free the memory of this structure in a loop, roughly like:

for (i = 0; i < teller; i++) {
   free((glycan+i)->desc);
}
free(glycan)

I assume that the pointers are still pointing to the empty memory blocks, therefore i wanted to set them to NULL as follows:

for (i = teller; i > 0; i--) {
    (glycan+i)->desc = NULL;
}
glycan = NULL;

Valgrind however tells me something which i don’t really understand:

==11783== Invalid write of size 4
==11783==    at 0x8048F49: main (spectral_matcher.c:122)
==11783==  Address 0x431c070 is 72 bytes inside a block of size 28,000 free'd
==11783==    at 0x4027C02: free (vg_replace_malloc.c:366)
==11783==    by 0x8048F2C: main (spectral_matcher.c:121)

Can anyone explain to me why this warning/error occurs and what i should do differently not to solve it?

EDIT: I am aware that i am setting the pointer to NULL after freeing, freeing only marks the memory as free so the pointer is still intact (if i’m not mistaking) which i subsequently wish to set to NULL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:21:24+00:00Added an answer on May 27, 2026 at 10:21 pm

    Once you free the variable glycan you can’t touch (glycan+i)->desc anymore – nor does it make sense.

    About the sense part: just think of it, if you say glycan = NULL, why would you care for the individual elements’ members ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some html which I would like to manipulate. Its structure is as
I have a complex regex, which contains constructs like this one: ( + sectionPattern
I have a directory structure like com/example/web under the root directory which contains a
seeking some advice here. I have a structure which contains a pointer to another
Lets say I have a structure like this: Object A contains an instance of
I have a database structure that has a Person table which contains fields such
I have a business object project, which contains composite structure: public class Tree {
I have a table T (structure below) which initially contains all-NULL values in an
I have a space separated file which contains some key->value pairs. These are to
I have three classes a) Parent - Which contains some properties, an Item collection

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.