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

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
Warnings : 1

Senior Member

Joined: 07 Feb 2009
Posts: 1266
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

Superior Member

Joined: 14 Mar 2007
Posts: 10803
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


#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));

    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


***** 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
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
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 Issued a CMD call for /DIS & it r... IMS DB/DC 3
No new posts Negative dependency between jobs in m... COBOL Programming 12
No new posts Looking for Mainframe programmers Mainframe Jobs 0
No new posts access Mainframe from .net application All Other Mainframe Topics 0
No new posts How to determine TLS/SSL version in m... TSO/ISPF 2
Search our Forums:

Back to Top