Skip to content

Commit 54b528b

Browse files
committed
Made static allocation and deallocation more consistent
1 parent 882f281 commit 54b528b

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

lib/postgresql_stubs.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ CAMLprim value PQconnectdb_stub(value v_conn_info, value v_startonly)
265265
caml_enter_blocking_section();
266266
conn = PQconnectdb(conn_info);
267267
cancel = PQgetCancel(conn);
268-
free(conn_info);
268+
caml_stat_free(conn_info);
269269
caml_leave_blocking_section();
270270
}
271271

@@ -466,8 +466,8 @@ static inline void copy_binary_params(
466466

467467
static inline void free_binary_params(int *formats, int *lengths)
468468
{
469-
if (formats != NULL) free(formats);
470-
if (lengths != NULL) free(lengths);
469+
if (formats != NULL) caml_stat_free(formats);
470+
if (lengths != NULL) caml_stat_free(lengths);
471471
}
472472

473473
static inline const char * const * copy_params(value v_params, size_t nparams)
@@ -493,7 +493,7 @@ static inline void free_params(const char * const *params, size_t nparams)
493493
size_t i;
494494
if (nparams == 0) return;
495495
for (i = 0; i < nparams; i++) caml_stat_free((char *) params[i]);
496-
free((char **) params);
496+
caml_stat_free((char **) params);
497497
}
498498

499499
static inline const char * const * copy_params_shallow(
@@ -514,7 +514,7 @@ static inline void free_params_shallow(
514514
const char * const *params, size_t nparams)
515515
{
516516
if (nparams == 0) return;
517-
free((char **) params);
517+
caml_stat_free((char **) params);
518518
}
519519

520520
CAMLprim value PQexecParams_stub(
@@ -538,7 +538,7 @@ CAMLprim value PQexecParams_stub(
538538
: PQexecParams(conn, query, nparams, NULL, params, lengths, formats, 0);
539539
free_binary_params(formats, lengths);
540540
free_params(params, nparams);
541-
free(query);
541+
caml_stat_free(query);
542542
caml_leave_blocking_section();
543543
CAMLreturn(alloc_result(res, np_cb));
544544
}
@@ -558,8 +558,8 @@ CAMLprim value PQprepare_stub(value v_conn, value v_stm_name, value v_query)
558558
memcpy(query, String_val(v_query), query_len);
559559
caml_enter_blocking_section();
560560
res = PQprepare(conn, stm_name, query, 0, NULL);
561-
free(stm_name);
562-
free(query);
561+
caml_stat_free(stm_name);
562+
caml_stat_free(query);
563563
caml_leave_blocking_section();
564564
CAMLreturn(alloc_result(res, np_cb));
565565
#else
@@ -588,7 +588,7 @@ CAMLprim value PQexecPrepared_stub(
588588
memcpy(stm_name, String_val(v_stm_name), len);
589589
caml_enter_blocking_section();
590590
res = PQexecPrepared(conn, stm_name, nparams, params, lengths, formats, 0);
591-
free(stm_name);
591+
caml_stat_free(stm_name);
592592
free_binary_params(formats, lengths);
593593
free_params(params, nparams);
594594
caml_leave_blocking_section();
@@ -615,7 +615,7 @@ CAMLprim value PQdescribePrepared_stub(value v_conn, value v_query)
615615
memcpy(query, String_val(v_query), len);
616616
caml_enter_blocking_section();
617617
res = PQdescribePrepared(conn, query);
618-
free(query);
618+
caml_stat_free(query);
619619
caml_leave_blocking_section();
620620
CAMLreturn(alloc_result(res, np_cb));
621621
#else
@@ -867,21 +867,21 @@ CAMLprim value PQescapeStringConn_stub(
867867
{
868868
size_t len = Long_val(v_len);
869869
size_t to_len = len + len + 1;
870-
char *buf = malloc(to_len);
870+
char *buf = caml_stat_alloc(to_len);
871871
int error;
872872
size_t n_written =
873873
PQescapeStringConn(
874874
get_conn(v_conn),
875875
buf, String_val(v_from) + Long_val(v_pos_from),
876876
len, &error);
877877
if (error) {
878-
free(buf);
878+
caml_stat_free(buf);
879879
caml_failwith("Postgresql.escape_string_conn: failed to escape string");
880880
return Val_unit;
881881
} else {
882882
value v_res = caml_alloc_string(n_written);
883883
memcpy(String_val(v_res), buf, n_written);
884-
free(buf);
884+
caml_stat_free(buf);
885885
return v_res;
886886
}
887887
}
@@ -1017,7 +1017,7 @@ CAMLprim value PQgetline_stub(
10171017
v_res = Val_int(PQgetline(conn, buf, len));
10181018
caml_leave_blocking_section();
10191019
memcpy(String_val(v_buf) + Long_val(v_pos), buf, len);
1020-
free(buf);
1020+
caml_stat_free(buf);
10211021
CAMLreturn(v_res);
10221022
}
10231023

@@ -1039,7 +1039,7 @@ CAMLprim value PQputline_stub(value v_conn, value v_buf)
10391039
memcpy(buf, String_val(v_buf), len);
10401040
caml_enter_blocking_section();
10411041
v_res = Val_int(PQputline(conn, buf));
1042-
free(buf);
1042+
caml_stat_free(buf);
10431043
caml_leave_blocking_section();
10441044
CAMLreturn(v_res);
10451045
}
@@ -1055,7 +1055,7 @@ CAMLprim value PQputnbytes_stub(
10551055
memcpy(buf, String_val(v_buf) + Long_val(v_pos), len);
10561056
caml_enter_blocking_section();
10571057
v_res = Val_int(PQputnbytes(conn, buf, len));
1058-
free(buf);
1058+
caml_stat_free(buf);
10591059
caml_leave_blocking_section();
10601060
CAMLreturn(v_res);
10611061
}
@@ -1131,7 +1131,7 @@ CAMLprim value lo_read_stub(value v_conn, value v_fd,
11311131
v_res = Val_long(lo_read(conn, Int_val(v_fd), buf, len));
11321132
caml_leave_blocking_section();
11331133
memcpy(String_val(v_buf) + Long_val(v_pos), buf, len);
1134-
free(buf);
1134+
caml_stat_free(buf);
11351135
CAMLreturn(v_res);
11361136
}
11371137

@@ -1160,7 +1160,7 @@ CAMLprim value lo_write_stub(value v_conn, value v_fd,
11601160
memcpy(buf, String_val(v_buf) + Long_val(v_pos), len);
11611161
caml_enter_blocking_section();
11621162
v_res = Val_long(lo_write(conn, Int_val(v_fd), buf, len));
1163-
free(buf);
1163+
caml_stat_free(buf);
11641164
caml_leave_blocking_section();
11651165
CAMLreturn(v_res);
11661166
}
@@ -1241,7 +1241,7 @@ CAMLprim value lo_import_stub(value v_conn, value v_fname)
12411241
memcpy(fname, String_val(v_fname), len);
12421242
caml_enter_blocking_section();
12431243
v_res = Val_int(lo_import(conn, fname));
1244-
free(fname);
1244+
caml_stat_free(fname);
12451245
caml_leave_blocking_section();
12461246
CAMLreturn(v_res);
12471247
}
@@ -1256,7 +1256,7 @@ CAMLprim value lo_export_stub(value v_conn, value v_oid, value v_fname)
12561256
memcpy(fname, String_val(v_fname), len);
12571257
caml_enter_blocking_section();
12581258
v_res = Val_int(lo_export(conn, Int_val(v_oid), fname));
1259-
free(fname);
1259+
caml_stat_free(fname);
12601260
caml_leave_blocking_section();
12611261
CAMLreturn(v_res);
12621262
}

0 commit comments

Comments
 (0)