Skip to content

caml_invalid_argument can't be used with dynamically allocated strings #7423

@vicuna

Description

@vicuna

Original bug ID: 7423
Reporter: @stijn-devriendt
Assigned to: @mshinwell
Status: closed (set by @mshinwell on 2016-12-27T09:18:35Z)
Resolution: duplicate
Priority: normal
Severity: feature
Platform: Linux
OS: Ubuntu
OS Version: 14.04
Version: 4.03.0
Category: runtime system and C interface
Monitored by: @gasche "Richard Jones"

Bug description

From https://sympa.inria.fr/sympa/arc/caml-list/2016-11/msg00106.html

caml_invalid_argument(str) is no return and does not free it's
argument. So calling it with a string constructed dynamically will mean it'll never get freed.
I could construct an ocaml string and pass that to caml_raise_with_arg,
but I don't seem to be able to get to the caml_exn_Invalid_argument from
c.

Reply from Gabriel Scherer:
It may make sense to have caml_{failwith,invalid_argument}_value
variants of the exception-raising functions that take a parameter, and
be implemented using caml_raise_with_arg(s) directly instead of
caml_raise_with_string. Could you open a mantis issue or submit a
github pull request to track the question and continue discussion?

Steps to reproduce

char* error = new char[50];
snprintf(error, 50, "error: %d", 50);
caml_invalid_argument(error)

allocated memory is lost here.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions