Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigarray data pointer not consistently allocated/deallocated in bigarray_stubs.c #3004

Closed
vicuna opened this issue Oct 31, 2001 · 2 comments
Closed
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 31, 2001

Original bug ID: 601
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Chris Hecker
Version: 3.03
OS: all
Submission from: node-d8e9cca2.powerinter.net (216.233.204.162)

The data pointer in the caml_bigarray struct is not allocated and deallocated
consistently in bigarray_stubs.c. Somtimes stat_alloc is used and sometimes
malloc is used, but stat_free is never used. For example, in the latest cvs
sources (Oct 30, 17:00 PST):

94: data = stat_alloc(size);
653: b->data = malloc(elt_size * num_elts);
400: free(b->data);
403: free(b->proxy->data);

It seems that stat_alloc/stat_free should always be used for consistency (and if
the runtime wants to do some tracking/debugging underneath).

Chris

@vicuna
Copy link
Author

vicuna commented Nov 26, 2001

Comment author: administrator

The data pointer in the caml_bigarray struct is not allocated and deallocated
consistently in bigarray_stubs.c. Somtimes stat_alloc is used and sometimes
malloc is used, but stat_free is never used. For example, in the latest cvs
sources (Oct 30, 17:00 PST):

94: data = stat_alloc(size);
653: b->data = malloc(elt_size * num_elts);
400: free(b->data);
403: free(b->proxy->data);

I agree it's a bit of a mess :-) We can't use stat_alloc() on line 653
because it may raise an exception, while we are not allowed to raise
exceptions in the middle of an input_value operation.

Concerning the free() on lines 400 and 403, the idea is that some C
code can create a Caml bigarray via alloc_bigarray, passing it data
allocated with the standard malloc(), and requesting (via the
BIGARRAY_MANAGED flag) that OCaml calls free() on the data when the
bigarray dies.

It seems that stat_alloc/stat_free should always be used for
consistency (and if the runtime wants to do some tracking/debugging
underneath).

I agree that stat_alloc and stat_free should always be used in pairs
for the reason you mention. Given the constraints I mentioned above,
this means that the stat_alloc on line 94 should be replaced by malloc
plus an explicit test on the result...

Best regards,

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Nov 26, 2001

Comment author: administrator

Fixed 2001-11-26 by XL

@vicuna vicuna closed this as completed Nov 26, 2001
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant