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 7007145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:34:11+00:00 2026-05-27T21:34:11+00:00

While using realloc(), I checked it with valgrind as follows valgrind –tool=memcheck –leak-check=yes –show-reachable=yes

  • 0

While using realloc(), I checked it with valgrind as follows

 valgrind --tool=memcheck --leak-check=yes --show-reachable=yes a.out

and the error information produced by valgrind is

==6402== Memcheck, a memory error detector.
==6402== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==6402== Using LibVEX rev 1575, a library for dynamic binary translation.
==6402== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==6402== Using valgrind-3.1.1, a dynamic binary instrumentation framework.
==6402== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==6402== For more details, rerun with: -v
==6402==
dinesh
vignesh
==6402== Invalid free() / delete / delete[]
==6402==    at 0x4905E12: realloc (vg_replace_malloc.c:306)
==6402==    by 0x400539: main (in /user/gur29597/mysourcecode/VMake/a.out)
==6402==  Address 0x7FF000830 is on thread 1's stack
vishwa
==6402==
==6402== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 1)
==6402== malloc/free: in use at exit: 0 bytes in 0 blocks.
==6402== malloc/free: 1 allocs, 1 frees, 3 bytes allocated.
==6402== For counts of detected errors, rerun with: -v
==6402== All heap blocks were freed -- no leaks are possible.

My code is as follows ,

#include<stdio.h>

int main()
{
  char *name[2];

 name[0]="dinesh";

 name[1]="vignesh";

  printf("%s\n%s\n",name[0],name[1]);

  realloc(name,3);

  name[2]="vishwa";

  printf("%s\n",name[2]);

 return 0;
}
  • 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-27T21:34:12+00:00Added an answer on May 27, 2026 at 9:34 pm

    Your program causes Undefined Behavior and valgrind correctly points it out.

    Reference:

    C99 Standard 7.20.3.4-1: The realloc function:

    Synopsis

    #include
    void *realloc(void *ptr, size_t size);

    Para 3:

    If ptr is a null pointer, the realloc function behaves like the malloc function for the specified size. Otherwise, ifptr does not match a pointer earlier returned by the calloc,malloc,or realloc function, or if the space has been deallocated by a call to the free or realloc function, the behavior is undefined. If memory for the newobject cannot be allocated, the old object is not deallocated and its value is unchanged.

    Note that in your case the pointer being passed to realloc is not null ans also was not received by calling calloc, malloc or realloc which breaks the requirements mandated by the standard hence the Undefined Behavior.

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

Sidebar

Related Questions

While using visualVM to detect memory leak, it allows us an Instance view as
While using Instruments, it seems like there is a leak coming from this method
While using Struts2, I am using several annotations to do my validations inside the
While using Vim (at home and at work), I often find myself doing similar
While using regex to help solve a problem in the Python Challenge , I
While using the vector why do we sometime use the operator[] like homework[mid] but
While using Aptana and Eclipse for the first time in my programming life for
While using fixed width select tag , there is one bug in IE. When
while using g.drawImage(img,0,0,100,100,0,0,0,0,null) it does not produce any result. So how to draw on
while using the following constructor $this->pdo = new PDO ($this->source, $this->username, $this->password); if I

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.