🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #1987

'Freeing' storage with realloc

#1987
From: Klaus Berndl
Date: Thu, 15 Feb 1996 15:01
38 lines
1262 bytes
Please look at the snipped of code:

#include <stdio.h>

main () {

  char* buf = NULL;

  buf = (char*)malloc(100);
  strcpy(buf, "Klaus Berndl");
  printf("\n%s\n", buf);

/* line 10 */  buf = (char*)realloc(buf, strlen(buf)+1);  /* line 10 */

  if (buf)
    printf("\n%s\n", buf);
  else
    printf("\nshit!\n");
}

My questions are now: How much memory is allocated for 'buf' after
executing line 10?! Does realloc 'freeing' the storage behind byte 13?
Or are still 100 bytes allocated for buf?

I`m working with Solaris 2.4 and SUNOS 4.1.3C


Many thanks in advance!


Ciao,
      Klaus

____________________________________________________________________________

Klaus Berndl                                e-mail: berndl@fmi.uni-passau.de
____________________________________________________________________________
Technical Details
Message-ID: <4fvhro$e7u@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: berndl@sidonius.fmi.uni-passau.de (Klaus Berndl)
Newsgroups: comp.lang.c.moderated
Subject: 'Freeing' storage with realloc
Date: 15 Feb 1996 09:01:12 -0600
Organization: University of Passau, Germany
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4fvhro$e7u@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com