LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-13-2005, 06:44 PM   #1
pierre-luc
LQ Newbie
 
Registered: Oct 2004
Location: Montreal
Distribution: Ubuntu
Posts: 25

Rep: Reputation: 15
Glibc free() invalid pointer


I can't figure out where an error is coming from. I'm stuck writing my program getting that error:

Quote:
*** glibc detected *** free(): invalid pointer: 0x0804b410 ***
Aborted
I tried to get some more clues about this passing the whole thing to valgrind:

Code:
==10868== Invalid write of size 4
==10868==    at 0x804961B: deltaWjkMod (neurone.c:206)
==10868==    by 0x8048B66: main (main.c:67)
==10868==  Address 0x1BCD1074 is 0 bytes after a block of size 12 alloc'd
==10868==    at 0x1B8FFB95: calloc (vg_replace_malloc.c:279)
==10868==    by 0x8048C3F: wmatriceCreer (neurone.c:27)
==10868==    by 0x80489A8: main (main.c:23)
==10868== 
==10868== Invalid free() / delete / delete[]
==10868==    at 0x1B8FF3D0: free (vg_replace_malloc.c:235)
==10868==    by 0x1BAACB7B: free_mem (in /lib/libc-2.3.4.so)
==10868==    by 0x1BAAC7D4: __libc_freeres (in /lib/libc-2.3.4.so)
==10868==    by 0x1B8FB6E0: _vgw_freeres (vg_preloaded.c:62)
==10868==    by 0x1B9E2585: exit (in /lib/libc-2.3.4.so)
==10868==    by 0x1B9CC470: __libc_start_main (in /lib/libc-2.3.4.so)
==10868==    by 0x80488C0: ??? (start.S:119)
==10868==  Address 0x1B913C90 is not stack'd, malloc'd or (recently) free'd
==10868== 
==10868== ERROR SUMMARY: 4 errors from 2 contexts (suppressed: 42 from 3)
==10868== malloc/free: in use at exit: 0 bytes in 0 blocks.
==10868== malloc/free: 15 allocs, 16 frees, 136 bytes allocated.
==10868== For counts of detected errors, rerun with: -v
==10868== No malloc'd blocks -- no leaks are possible.
As far as GDB is concerned, I don't get much more information:
Code:
Program received signal SIGABRT, Aborted.
0x400f4ef1 in kill () from /lib/libc.so.6
The line (206) reported by valgrind is the following:
Code:
      net->wjk->wMatrice[k][i] = (net->n) * (net->cachee->delta[i]);
Inside a small function:
Code:
void
deltaWjkMod (struct reseau *net)
{
  int i, k;
  for (i = 0; i < net->nCachee + 1; i++)
    for (k = 0; k < net->nEntree + 1; k++)
      net->wjk->wMatrice[k][i] = (net->n) * (net->cachee->delta[i]);
}
What's going wrong here ? I can understand what that error could mean but I can't see what I'm not doing right.

The source code can be seen here:

http://pierreluc.aqra.ca/projet/BackPropNN/
 
Old 11-13-2005, 07:09 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
i dont know if this is the answer but from what i see your func
Code:
void
deltaWjk (struct reseau *net)
{
  int i, j, k;
  float sum = 0;

  for (j = 0; j < net->nCachee + 1; j++)
    {
      sum = 0;
      for (i = 0; i < net->nSortie; i++)
	sum += net->sortie->delta[i] * net->wij->wMatrice[j][i];
      for (k = 0; k < net->nEntree + 1; k++)
	net->cachee->delta[j] +=
	  (net->cachee->couche[j]) * (1 -
				      net->cachee->couche[j]) * sum *
	  (net->entree->couche[k]);
    }
}
is accessing memory passed the size of a float on the delta( net->cachee->delta[i] )
delta is a pointer to a float which is created in cCacheeCreer. is this correct? if so you are only creating a pointer to a single float. but i dont see why this would give a free error unless you then try and free past delta.
post back if i have missed something.
 
Old 11-13-2005, 07:57 PM   #3
pierre-luc
LQ Newbie
 
Registered: Oct 2004
Location: Montreal
Distribution: Ubuntu
Posts: 25

Original Poster
Rep: Reputation: 15
Delta is a float pointer to a dynamic array created inside main function within cCacheeCreer or cSortieCreer.

Code:
  cCachee.delta = cCacheeCreer (&cCachee);
thanks for your feedback
 
Old 11-13-2005, 08:04 PM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
so it is, im so used to using c++ i keep forgeting c style memory .oops
 
  


Reply



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
*** glibc detected *** malloc() / free()/ double RohanShrivastav Programming 12 10-01-2012 10:08 AM
FC3 glibc detected *** double free or corruption: josedragone Fedora 5 09-17-2009 10:16 PM
free pointer os2 Programming 1 02-23-2005 09:07 AM
OpenOffice.org *** glibc detected *** free(): invalid pointer: 0x41481c94 *** Artanicus Linux - Software 2 02-19-2005 07:04 PM
OpenOffice.Org 1.1.2 + Linux2.4.28 = Invalid Pointer wpyh Linux - Software 1 11-25-2004 09:32 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:21 AM.

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