Skip to content

Commit fb21137

Browse files
committed
Adrian Pop, adrpo@ida.liu.se
2004-10-29 --------------------------------------------------------------> /modelica/modeq/runtime/systemimpl.c --------------------------------------------------------------> - RML_BEGIN_LABEL(System__read_5ffile) + free of buf not done - RML_BEGIN_LABEL(System__strtok) + free of str not done after strdup - RML_BEGIN_LABEL(System__toupper) + free of res not done after strdup - RML_BEGIN_LABEL(System__sub_5fdirectories) + free of files[i] not done - RML_BEGIN_LABEL(System__mo_5ffiles) + free of files[i] not done - i guess usages of rml_prim_once should be replaced by TAILCALL with prior setting of SC because rml_prim_once uses longjump to go to the function and saves unnecessary information git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1329 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 02c8906 commit fb21137

File tree

1 file changed

+43
-12
lines changed

1 file changed

+43
-12
lines changed

modeq/runtime/systemimpl.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,22 @@ RML_BEGIN_LABEL(System__strtok)
143143

144144
void * res = (void*)mk_nil();
145145
s=strtok(str,delimit);
146-
if (s == NULL) { rmlA0=res; RML_TAILCALLK(rmlFC); }
146+
if (s == NULL)
147+
{
148+
/* adrpo added 2004-10-27 */
149+
free(str);
150+
rmlA0=res; RML_TAILCALLK(rmlFC);
151+
}
147152
res = (void*)mk_cons(mk_scon(s),res);
148-
while (s=strtok(NULL,delimit)) {
153+
while (s=strtok(NULL,delimit))
154+
{
149155
res = (void*)mk_cons(mk_scon(s),res);
150156
}
151157
rmlA0=res;
152158

159+
/* adrpo added 2004-10-27 */
160+
free(str);
161+
153162
rml_prim_once(RML__list_5freverse);
154163

155164
RML_TAILCALLK(rmlSC);
@@ -160,10 +169,15 @@ RML_BEGIN_LABEL(System__toupper)
160169
{
161170
char *str = strdup(RML_STRINGDATA(rmlA0));
162171
char *res=str;
163-
while (*str!= '\0') {
172+
while (*str!= '\0')
173+
{
164174
*str=toupper(*str++);
165175
}
166176
rmlA0 = (void*) mk_scon(res);
177+
178+
/* adrpo added 2004-10-29 */
179+
free(res);
180+
167181
RML_TAILCALLK(rmlSC);
168182
}
169183
RML_END_LABEL
@@ -279,21 +293,29 @@ RML_BEGIN_LABEL(System__read_5ffile)
279293
struct stat statstr;
280294
res = stat(filename, &statstr);
281295

282-
if(res!=0){
296+
if(res!=0)
297+
{
283298
rmlA0 = (void*) mk_scon("No such file");
284299
RML_TAILCALLK(rmlSC);
285300
}
286301

287302
file = fopen(filename,"rb");
288303
buf = malloc(statstr.st_size+1);
289304

290-
if( (res = fread(buf, sizeof(char), statstr.st_size, file)) != statstr.st_size){
305+
if( (res = fread(buf, sizeof(char), statstr.st_size, file)) != statstr.st_size)
306+
{
307+
/* adrpo added 2004-10-26 */
308+
free(buf);
291309
rmlA0 = (void*) mk_scon("Failed while reading file");
292310
RML_TAILCALLK(rmlSC);
293311
}
294312
buf[statstr.st_size] = '\0';
295313
fclose(file);
296314
rmlA0 = (void*) mk_scon(buf);
315+
316+
/* adrpo added 2004-10-26 */
317+
free(buf);
318+
297319
RML_TAILCALLK(rmlSC);
298320
}
299321
RML_END_LABEL
@@ -305,6 +327,7 @@ RML_BEGIN_LABEL(System__modelicapath)
305327
RML_TAILCALLK(rmlFC);
306328

307329
rmlA0 = (void*) mk_scon(path);
330+
308331
RML_TAILCALLK(rmlSC);
309332
}
310333
RML_END_LABEL
@@ -313,10 +336,12 @@ RML_BEGIN_LABEL(System__read_5fenv)
313336
{
314337
char* envname = RML_STRINGDATA(rmlA0);
315338
char *envvalue = getenv(envname);
316-
if (envvalue == NULL) {
339+
if (envvalue == NULL)
340+
{
317341
RML_TAILCALLK(rmlFC);
318342
}
319343
rmlA0 = (void*) mk_scon(envvalue);
344+
320345
RML_TAILCALLK(rmlSC);
321346
}
322347
RML_END_LABEL
@@ -352,11 +377,14 @@ RML_BEGIN_LABEL(System__sub_5fdirectories)
352377
if (directory == NULL)
353378
RML_TAILCALLK(rmlFC);
354379
select_from_dir = directory;
355-
count =
356-
scandir(directory, &files, file_select_directories,NULL);
380+
count = scandir(directory, &files, file_select_directories, NULL);
357381
res = (void*)mk_nil();
358-
for (i=0; i<count; i++) {
382+
for (i=0; i<count; i++)
383+
{
359384
res = (void*)mk_cons(mk_scon(files[i]->d_name),res);
385+
/* adrpo added 2004-10-28 */
386+
//free(files[i]->d_name);
387+
free(files[i]);
360388
}
361389
rmlA0 = (void*) res;
362390
RML_TAILCALLK(rmlSC);
@@ -392,11 +420,14 @@ RML_BEGIN_LABEL(System__mo_5ffiles)
392420
if (directory == NULL)
393421
RML_TAILCALLK(rmlFC);
394422
select_from_dir = directory;
395-
count =
396-
scandir(directory, &files, file_select_mo,NULL);
423+
count = scandir(directory, &files, file_select_mo, NULL);
397424
res = (void*)mk_nil();
398-
for (i=0; i<count; i++) {
425+
for (i=0; i<count; i++)
426+
{
399427
res = (void*)mk_cons(mk_scon(files[i]->d_name),res);
428+
/* adrpo added 2004-10-28 */
429+
//free(files[i]->d_name);
430+
free(files[i]);
400431
}
401432
rmlA0 = (void*) res;
402433
RML_TAILCALLK(rmlSC);

0 commit comments

Comments
 (0)