Opened 12 years ago

Closed 12 years ago

#2150 closed defect (fixed)

Copy back data from external integer arrays

Reported by: Willi Braun Owned by: Martin Sjölund
Priority: high Milestone: 1.9.0
Component: Backend Version: trunk
Keywords: Cc: Martin Sjölund

Description (last modified by Willi Braun)

following model generates memory leaks for Integer values.

system("echo \"void extIntegerArray(int* a, int n, int* out){int i;for(i=0;i<n;i++){out[i] = a[i]+i;}}\" > ExtIntegerArrayFunc.c");
loadString("

function extIntegerArray
  input Integer x[:];
  input Integer s;
  output Integer y[size(x,1)];
  external \"C\" extIntegerArray(x,s,y) annotation(Library=\"libExtIntegerArrayFunc1_ext.a\");
end extIntegerArray;

model A
  function extIntArray
    input Integer x[:];
    input Integer s;
    output Integer y[size(x,1)];
  algorithm
    y := extIntegerArray(x,s);
  end extIntArray;

  Integer ints[:] = {integer(2*time),integer(1*time),3,5,7,8,3};
  Integer ou1[size(ints,1)];

equation
  ou1 = extIntArray(ints,size(ints,1));
end A;");
getErrorString();

system("gcc -c -o libExtIntegerArrayFunc1_ext.a ExtIntegerArrayFunc.c");
simulate(A, stopTime=0.1, numberOfIntervals=2);
system("valgrind ./A");
getErrorString();

it's the usage of data_of_integer_array in util/inter_array.h that produces memory leaks.

Change History (3)

comment:1 by Willi Braun, 12 years ago

Cc: Martin Sjölund added
Description: modified (diff)

comment:2 by Martin Sjölund, 12 years ago

Owner: changed from probably noone to Martin Sjölund
Status: newaccepted
Summary: external function produces memory leaksexternal function does not produce memory leaks

A memory leak is when we allocate memory that we cannot reclaim. In this case, we assign to one piece of allocated memory, and subsequently free it without copying it to the correct place.
I have a fix in place; running the testsuite overnight.

comment:3 by Martin Sjölund, 12 years ago

Resolution: fixed
Status: acceptedclosed
Summary: external function does not produce memory leaksCopy back data from external integer arrays

Fixed in r15872

Note: See TracTickets for help on using tickets.