![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 'memory corruption' error when using Awk | kooyee | UNIX for Dummies Questions & Answers | 5 | 07-09-2009 01:36 PM |
| OS is not detected CPU and memory | arumsun | SUN Solaris | 1 | 06-29-2009 06:15 AM |
| Pointer to a struct (with pointers) *** glibc detected *** double free | jatoo | High Level Programming | 1 | 12-05-2008 08:31 AM |
| *** glibc detected *** double free or corruption: 0x40236ff4 *** | norsk hedensk | High Level Programming | 19 | 11-14-2008 01:43 PM |
| *** glibc detected *** free(): invalid next size (normal): 0x0000000000503e70 *** | vbreddy | High Level Programming | 1 | 04-11-2006 01:18 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Quote:
Code:
static void make_vertex(vertex **ver, int index, int s, int ps)
{
ver = (vertex **)malloc(sizeof(vertex *));
if (ver == NULL)
exit(1);
*ver = (vertex *)malloc(sizeof(vertex));
if ( *ver == NULL ) {
printf("memory allocation error\n");
exit(1);
}
(*ver)->id = index;
(*ver)->seq = s;
(*ver)->pos = ps;
(*ver)->clique = 0;
(*ver)->numOfPrev = 0;
(*ver)->numOfVer = 0;
(*ver)->numOfNext = 0;
(*ver)->prev = NULL;
(*ver)->next = NULL;
(*ver)->front = NULL;
(*ver)->back = NULL;
(*ver)->left = NULL;
(*ver)->right = NULL;
}
|
|
||||
|
Quote:
Code:
vertex *root; root = make_vertex(&root,-1,0,-1); For this you need to change the definition of make_vertex to return a pointer to vertex instead of void. |
|
||||
|
Add return statement and change return type and it can work. But it still fails after generating many vertices. Notice where failure occurs This seems to be a general problem. Thanks for all your help ____________________________________ Program received signal SIGSEGV, Segmentation fault. 0x0027ff92 in _int_malloc () from /lib/tls/libc.so.6 (gdb) bt #0 0x0027ff92 in _int_malloc () from /lib/tls/libc.so.6 #1 0x0027f0fd in malloc () from /lib/tls/libc.so.6 #2 0x0804956e in make_vertex (ver=0xbfffb624, index=-1, se=0, ps=2) Code:
vertex *root;
root = make_vertex(&root, -1, 0, -1);
static vertex* make_vertex(vertex **ver, int index, int s, int ps)
{
ver = (vertex **)malloc(sizeof(vertex *)); //Here:fails
if (ver == NULL)
exit(1);
*ver = (vertex *)malloc(sizeof(vertex));
if ( *ver == NULL ) {
printf("memory allocation error\n");
exit(1);
}
(*ver)->id = index;
(*ver)->seq = s;
(*ver)->pos = ps;
(*ver)->clique = 0;
(*ver)->numOfPrev = 0;
(*ver)->numOfVer = 0;
(*ver)->numOfNext = 0;
(*ver)->prev = NULL;
(*ver)->next = NULL;
(*ver)->front = NULL;
(*ver)->back = NULL;
(*ver)->left = NULL;
(*ver)->right = NULL;
return *ver;
}
---------- Post updated at 12:37 PM ---------- Previous update was at 11:01 AM ---------- Tried to use make_vertex. It can change memory in this way. A new trouble takes place. Allocation really gives unexpected problems. dataset[4] changes __________________________________________________________________ 110 r = make_vertex(&rho, -1, 0, i); (gdb) p *(dataset+3) $33 = 0x8145200 "AATTGTAAC" (gdb) p *(dataset+4) $34 = 0x8145a30 "GCTGAATGA" (gdb) n 111 first = rho; (gdb) p *(dataset+3) $35 = 0x8145200 "AATTGTAAC" (gdb) p *(dataset+4) $36 = 0xb25a90 "\210Zē" Last edited by cdbug; 4 Weeks Ago at 03:17 PM.. |
|
||||
|
Quote:
Code:
static vertex* make_vertex( int index, int s, int ps )
{
vertex *ver;
ver = ( vertex * ) calloc( sizeof( vertex ) );
if ( NULL != ver )
{
ver->id = index;
ver->seq = s;
ver->pos = ps;
}
return( ver );
}
If THAT blows up, your heap is getting corrupted before you even make the call to make_vertex(). |
|
||||
|
I change make_vertex as you showed. It appears to work well. But dataset is destructed. This also gives troubles since it is what the code works on
dataset[4] has a different address after a call to make_vertex _______________________________________________________________ (gdb) p dataset[4] $1 = 0x8b91a30 "GCTGAATGA" (gdb) n (gdb) p dataset[4] $2 = 0x792a90 "\210*y" |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|