IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Print call stack in Mainframe C


IBM Mainframe Forums -> ABENDS & Debugging
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
DIPANKAR SAHA

New User


Joined: 15 Mar 2018
Posts: 1
Location: India

PostPosted: Thu Mar 15, 2018 2:58 pm
Reply with quote

My C program is failing because of memory abend. Can i print the call stack at the time of failure like which function asked the memory that cause the fail ?
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1306
Location: Vilnius, Lithuania

PostPosted: Thu Mar 15, 2018 4:16 pm
Reply with quote

Since when can memory abend? You're on a forum for experts, tell us what really happened and don't invent fake descriptions!
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Mar 15, 2018 6:53 pm
Reply with quote

if instead of a generic whining You had posted the messages received
it would have been easier for us to answer.

a C program abending on a malloc/free is a badly written program ...
a malloc returns the address of the malloced storage/memory
after a malloc the program should check for a not NULL value
and behave accordingly
before issuing a free a well behaved program should check for a non NULL storage/memory pointer

here is a snippet to show what I am talking about

Code:

#include <inttypes.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

int main()
{
    uint8_t *area ;
    int      areasize = 16*1024*1024 ;

    uint8_t *null ;

    printf( "***** start of test *****\n");

    printf( "before malloc a %d area\n", areasize );
    area = malloc( areasize );
    if (area == NULL)
    {
        fprintf (stderr,
                "Cannot obtain a %d area: %s\n",
                areasize, strerror(errno));
        exit(1);
    }

    printf( "before free a %d area\n", areasize );

    if (area != NULL)
        free( area );
   
   /* area = NULL; */

    printf( "***** end of test *****\n");

    free( area );

    exit( 0) ;

}


the free after the end of test was added to show what happens
when trying to free an invalid storage/memory pointer

Code:

***** start of test *****
before malloc a 16777216 area
before free a 16777216 area
***** end of test *****
a.out(91122,0x7fffa2b75340) malloc: *** error for object 0x10eee6000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6


BUT if You uncomment the area = NULL statement
free will not complain and just ignore the free

from the free man page
Quote:
The free() function deallocates the memory allocation pointed to by ptr.
If ptr is a NULL pointer, no operation is performed.


summarizing the whole shebang
ALWAYS CHECK THE RETURNED POINTER FOR NULL
AFTER A FREE ALWAYS SET THE POINTER TO NULL
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> ABENDS & Debugging

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 4
No new posts Mainframe openings in Techmahnidra fo... Mainframe Jobs 0
No new posts How to get a stack trace on a looping... ABENDS & Debugging 5
No new posts JCL sortcard to print only the records DFSORT/ICETOOL 11
No new posts Error while running web tool kit REXX... CLIST & REXX 5
Search our Forums:

Back to Top