The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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 12:36 PM
OS is not detected CPU and memory arumsun SUN Solaris 1 06-29-2009 05: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 12:18 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 3 Weeks Ago
cdbug cdbug is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 52
Why does this occur? *** glibc detected *** malloc(): memory corruption: 0x10013ff8 ***

there seems not to be error in this segment. In some computers, it can work well. But in others, it will give a failure.

why it ocurrs and how to deal with it?


in a function:
Code:
        if( *ver == NULL ) {
                *ver = (vertex *) malloc(sizeof(vertex));    //this line
                if( *ver == NULL ) {
                        printf("memory allocation error\n");
                }
        }

Last edited by pludi; 3 Weeks Ago at 08:15 AM.. Reason: code tags, please
  #2 (permalink)  
Old 3 Weeks Ago
pogdorica's Avatar
pogdorica pogdorica is online now
Registered User
  
 

Join Date: Oct 2009
Location: Madrid
Posts: 54
Quote:
Originally Posted by cdbug View Post
there seems not to be error in this segment. In some computers, it can work well. But in others, it will give a failure.

why it ocurrs and how to deal with it?


in a function:
Code:
        if( *ver == NULL ) {
                *ver = (vertex *) malloc(sizeof(vertex));    //this line
                if( *ver == NULL ) {
                        printf("memory allocation error\n");
                }
        }


//tabs can not work
Hi. Is this better ?

Code:
if( ver == NULL ) 
{
   ver = (vertex *) malloc(sizeof(vertex));
   if(  ver == NULL ) 
   {
      printf("memory allocation error\n");
   }
 }

Last edited by vbe; 3 Weeks Ago at 10:02 AM.. Reason: added code tags in quote...
  #3 (permalink)  
Old 3 Weeks Ago
cdbug cdbug is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 52
does not make effect. should generate many vertices for a graph. but it will fail after 20 vertices.

can generate 20 vertices. after then, it fails. can't figure out.
  #4 (permalink)  
Old 3 Weeks Ago
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Can you post more of your code including the typedef of vertex...and on which platforms does it fail.
  #5 (permalink)  
Old 3 Weeks Ago
cdbug cdbug is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 52
Linux 3.2.3-59

Code:

struct  vertex {
        int id;
        int seq;
        int pos;
        int clique;
        int numOfVer;
        int numOfPrev;
        int numOfNext;
        int *prev;
        int *next;
        vertex *front;
        vertex *back;
        vertex *left;
        vertex *right;
};

static void make_vertex(vertex **ver, int index, int s, int ps) {
       
        *ver = NULL;
        if( *ver == NULL ) {
                *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;
}
Regards

Last edited by cdbug; 3 Weeks Ago at 11:55 AM..
  #6 (permalink)  
Old 3 Weeks Ago
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
Quote:
Originally Posted by cdbug View Post
Linux 3.2.3-59

Code:

struct  vertex {
        int id;
        int seq;
        int pos;
        int clique;
        int numOfVer;
        int numOfPrev;
        int numOfNext;
        int *prev;
        int *next;
        vertex *front;
        vertex *back;
        vertex *left;
        vertex *right;
};

static void make_vertex(vertex **ver, int index, int s, int ps) {
       
        *ver = NULL;
        if( *ver == NULL ) {
                *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;
}
Regards
Allocate storage for ver before mallocing memory for *ver as ver maybe pointing to some arbitrary location producing the malloc corruption.
  #7 (permalink)  
Old 3 Weeks Ago
cdbug cdbug is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 52
where and how should this be done? Would you please give an example?

Thanks
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:54 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0