0

I am executing Proc code in unix server, the proc will read the record from file and store the data in array of structure and after some processing it will produce the output. When i read 368700 records from the file and process in the code means its executing fine. but when i try to read 370000 records from the file and process means, I am getting an error saying ORA-12533: TNS:illegal ADDRESS parameters and illegal address. What could be the cause and possible solution for this error?

I've done memory allocation like below:

 int unsigned long  size=(atoi(argv[2]))+1;
 printf("\nthe size is %lu",size);
 printf("\n am here 1");
 what_if_var =(what_if*)malloc((size)*sizeof(what_if));
 temp_var    =(what_if*)malloc((size)*sizeof(what_if));
Shweta
  • 5,198
  • 11
  • 44
  • 58
jcrshankar
  • 83
  • 2
  • 6
  • 2
    did you check if the memory was allocated by checking if malloc returns NULL or not? – phoxis May 13 '11 at 08:08
  • 1
    The type of size should probably be size_t. – edgar.holleis May 13 '11 at 08:18
  • 1
    The error is probably not in the code shown here. You have a bug somewhere else, but it's hard to guess where. The error says you're trying to access memory you shouldn't - which is a very broad and general error, and can happen pretty much anywhere in your code. (e.g. if malloc fails and you don't handle it, if you step past an array, etc) – nos May 13 '11 at 08:23
  • if( (what_if_var =malloc((size)*sizeof(what_if)))== NULL) { exit( -1 ); } if((temp_var =malloc((size)*sizeof(what_if)))== NULL) { exit( -1 ); } when i gave argv[2] as 368000 its working fine but failed when i gave 400000 – jcrshankar May 13 '11 at 10:13
  • program got exit from the code – jcrshankar May 13 '11 at 10:13
  • how big is the what_if struct? – EmeryBerger May 13 '11 at 13:09

2 Answers2

1
  1. Don't cast the return value of malloc() in C.
  2. It's better to write sizeof *what_if_var in the call to malloc(), in case the type of what_if_var isn't really what_if.
  3. Always check that you didn't get a NULL pointer back, in case of low memory allocations can fail.
  4. Investigate if there perhaps is a limit to how much RAM a process can use, some sysadmins do this on shared machines.
  5. Use size_t to hold sizes, it's the type of malloc()'s argument so it makes sense.
Community
  • 1
  • 1
unwind
  • 391,730
  • 64
  • 469
  • 606
0

You should check if malloc returned NULL, it means that there is not available memory to be allocated. You should free the memory with data that you will not use again with the function free().

The memory limit depends of the operating system and its configuration. The limit of memory of a 32-bit process may be 2 GB or 4 GB.

Squall
  • 4,344
  • 7
  • 37
  • 46