Skip to content
Snippets Groups Projects
Commit faabb764 authored by Oliver Sander's avatar Oliver Sander
Browse files

Do not allocate arrays of size WOP_DOWN_CHANNELS_MAX on the stack.

Allocate them on the heap instead.  I want't to make the _MAX value
much larger, to accommodate for higher processors numbers.
Allocating arrays of that size on the stack would possibly make
the stack overflow.

[[Imported from SVN: r8459]]
parent 22539ed6
No related branches found
No related tags found
No related merge requests found
...@@ -17796,12 +17796,17 @@ static INT CollectCoarseGrid(MULTIGRID *mg, INT MarkKeyMaster) ...@@ -17796,12 +17796,17 @@ static INT CollectCoarseGrid(MULTIGRID *mg, INT MarkKeyMaster)
INT MarkBottomKey; INT MarkBottomKey;
   
/* state information */ /* state information */
INT receiving[WOP_DOWN_CHANNELS_MAX], sending[WOP_DOWN_CHANNELS_MAX+1], INT* receiving = (INT*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(INT));
nbTokens[WOP_DOWN_CHANNELS_MAX], more[WOP_DOWN_CHANNELS_MAX+1], INT* sending = (INT*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(INT));
count[WOP_DOWN_CHANNELS_MAX+1], front[WOP_DOWN_CHANNELS_MAX+1], INT* nbTokens = (INT*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(INT));
rear[WOP_DOWN_CHANNELS_MAX+1]; INT* more = (INT*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(INT));
int serror[WOP_DOWN_CHANNELS_MAX+1], rerror[WOP_DOWN_CHANNELS_MAX]; INT* count = (INT*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(INT));
msgid outmsg[WOP_DOWN_CHANNELS_MAX+1], inmsg[WOP_DOWN_CHANNELS_MAX]; INT* front = (INT*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(INT));
INT* rear = (INT*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(INT));
int* serror = (int*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(int));
int* rerror = (int*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(int));
msgid* outmsg = (msgid*)malloc((WOP_DOWN_CHANNELS_MAX+1)*sizeof(msgid));
msgid* inmsg = (msgid*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(msgid));
   
/* init */ /* init */
elem = FIRSTELEMENT(GRID_ON_LEVEL(mg,0)); elem = FIRSTELEMENT(GRID_ON_LEVEL(mg,0));
...@@ -17825,6 +17830,17 @@ oops: ...@@ -17825,6 +17830,17 @@ oops:
if (error) { if (error) {
Release(heap,FROM_BOTTOM,MarkBottomKey); Release(heap,FROM_BOTTOM,MarkBottomKey);
UserWrite("CollectCoarseGrid(): error in stage 0\n"); UserWrite("CollectCoarseGrid(): error in stage 0\n");
free(receiving);
free(sending);
free(nbTokens);
free(more);
free(count);
free(front);
free(rear);
free(serror);
free(rerror);
free(outmsg);
free(inmsg);
return 1; return 1;
} }
for (i=0; i<WopDownChannels; i++) { for (i=0; i<WopDownChannels; i++) {
...@@ -18010,6 +18026,19 @@ oops: ...@@ -18010,6 +18026,19 @@ oops:
} }
} }
Release(heap,FROM_BOTTOM,MarkBottomKey); Release(heap,FROM_BOTTOM,MarkBottomKey);
free(receiving);
free(sending);
free(nbTokens);
free(more);
free(count);
free(front);
free(rear);
free(serror);
free(rerror);
free(outmsg);
free(inmsg);
return error; return error;
} }
#endif #endif
...@@ -21079,8 +21108,8 @@ static void ConnectWopTree(void) ...@@ -21079,8 +21108,8 @@ static void ConnectWopTree(void)
   
static void NumberOfDesc(void) static void NumberOfDesc(void)
{ {
msgid umid, dmid[WOP_DOWN_CHANNELS_MAX]; msgid* umid, dmid;
int uerr, derr[WOP_DOWN_CHANNELS_MAX]; int* uerr, derr;
INT sum; INT sum;
INT i, noDesc; INT i, noDesc;
   
...@@ -21090,6 +21119,12 @@ static void NumberOfDesc(void) ...@@ -21090,6 +21119,12 @@ static void NumberOfDesc(void)
noDesc = (noDesc && WOP_DownChannel[i] == NULL); noDesc = (noDesc && WOP_DownChannel[i] == NULL);
} }
if (procs < 2) return; if (procs < 2) return;
umid = (msgid*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(msgid));
dmid = (msgid*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(msgid));
uerr = (int*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(int));
derr = (int*)malloc(WOP_DOWN_CHANNELS_MAX*sizeof(int));
if (noDesc) { if (noDesc) {
sum = 1; sum = 1;
umid = SendASync(WOP_UpChannel, &sum, sizeof(sum), &uerr); umid = SendASync(WOP_UpChannel, &sum, sizeof(sum), &uerr);
...@@ -21114,6 +21149,12 @@ static void NumberOfDesc(void) ...@@ -21114,6 +21149,12 @@ static void NumberOfDesc(void)
while (InfoASend(WOP_UpChannel, umid) != 1); while (InfoASend(WOP_UpChannel, umid) != 1);
} }
} }
/* Release heap memory */
free umid;
free dmid;
free uerr;
free derr;
} }
   
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment