LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise
User Name
Password
Linux - Enterprise This forum is for all items relating to using Linux in the Enterprise.

Notices


Closed Thread
  Search this Thread
Old 08-05-2010, 10:57 AM   #1
rahulvishwakarma
Member
 
Registered: Aug 2010
Posts: 139

Rep: Reputation: 2
Exclamation invalid pointer error


/*

hey dude error in gnu c pointer please solve this

I am using Red Hat Enterprise Linux 5.0.

*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
char * cp = NULL;

cp = (char*)malloc(11);

cp = "abcdefgh";

printf(" cp = %s \n",cp);

free(cp);

return 0;
}
________________________________________________________________________




gives an error of stack overflow problem :-
_______________________________

*** glibc detected *** ./pointer: free(): invalid pointer: 0x08048510 ***
======= Backtrace: =========
/lib/libc.so.6[0x9a0b16]
/lib/libc.so.6(cfree+0x90)[0x9a4030]
./pointer[0x8048430]
/lib/libc.so.6(__libc_start_main+0xdc)[0x94ddec]
./pointer[0x8048331]
======= Memory map: ========
00110000-00111000 r-xp 00110000 00:00 0 [vdso]
00915000-0092f000 r-xp 00000000 03:05 2524560 /lib/ld-2.5.so
0092f000-00930000 r-xp 00019000 03:05 2524560 /lib/ld-2.5.so
00930000-00931000 rwxp 0001a000 03:05 2524560 /lib/ld-2.5.so
00938000-00a75000 r-xp 00000000 03:05 2524561 /lib/libc-2.5.so
00a75000-00a77000 r-xp 0013d000 03:05 2524561 /lib/libc-2.5.so
00a77000-00a78000 rwxp 0013f000 03:05 2524561 /lib/libc-2.5.so
00a78000-00a7b000 rwxp 00a78000 00:00 0
00d2b000-00d36000 r-xp 00000000 03:05 2524570 /lib/libgcc_s-4.1.2-20080102.so.1
00d36000-00d37000 rwxp 0000a000 03:05 2524570 /lib/libgcc_s-4.1.2-20080102.so.1
08048000-08049000 r-xp 00000000 03:02 32980 /softwares/data/C/pointer
08049000-0804a000 rw-p 00000000 03:02 32980 /softwares/data/C/pointer
09755000-09776000 rw-p 09755000 00:00 0
b7e00000-b7e21000 rw-p b7e00000 00:00 0
b7e21000-b7f00000 ---p b7e21000 00:00 0
b7fde000-b7fe0000 rw-p b7fde000 00:00 0
b7ff5000-b7ff6000 rw-p b7ff5000 00:00 0
bfdd7000-bfdec000 rw-p bfdd7000 00:00 0 [stack]
Aborted



http://stackoverflow.com/questions/ask/submit
 
Old 08-05-2010, 11:25 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Code:
/*
 * Hey, dude - Movie recommendation
 */
  // 1) Declare character pointer - good!
  char * cp = NULL;

  // 2) Allocate space to hold up to 10 characters - good!
  cp = (char*)malloc(11);

  // 3) Assign a static string to the pointer.
  //    OK .. but you just undid step 2).  Why?
  //    And you just ORPHANED your allocated block - bad.  Memory leak!
  acp = "abcdefgh";

  // 4) Print the string - OK
  printf(" cp = %s \n",cp);

  // 5) Free the string - bad!
  //    cp now points to the static string - NOT the allocated block!
  free(cp);

Last edited by paulsm4; 08-05-2010 at 11:31 AM.
 
Old 08-06-2010, 11:18 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603Reputation: 3603
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.
 
  


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error : glibc invalid pointer error gpfdez83 Programming 3 11-04-2009 03:48 PM
phusion passenger module generating invalid pointer error cozcol Linux - Newbie 0 04-14-2009 07:39 PM
Error during cimserver start : *** glibc detected *** realloc(): invalid pointer MaverickLikesMustang Linux - Software 0 02-14-2008 07:42 AM
glibc detected : Invalid Pointer Error DragonM15 Linux - Software 3 06-01-2007 01:43 AM
Marble Blast Demo (glibc invalid pointer error) KRiSX.cjb.net Linux - Games 1 05-24-2006 06:53 AM

LinuxQuestions.org > Forums > Enterprise Linux Forums > Linux - Enterprise

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration