move allocation of talloc contexts into link-time constructor
This is much more optimal than checking if the context exists every
time we allocate the respective object.
diff --git a/openbsc/src/gsm_04_11.c b/openbsc/src/gsm_04_11.c
index 8db402b..9218783 100644
--- a/openbsc/src/gsm_04_11.c
+++ b/openbsc/src/gsm_04_11.c
@@ -162,19 +162,11 @@
u_int8_t address_lv[12]; /* according to 03.40 / 9.1.2.5 */
int rc = 0;
- if (!tall_sms_ctx)
- tall_sms_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "sms_submit");
-
sms = talloc(tall_sms_ctx, struct sms_submit);
if (!sms)
return -ENOMEM;
memset(sms, 0, sizeof(*sms));
- if (!tall_gsms_ctx)
- tall_gsms_ctx = talloc_named_const(tall_bsc_ctx, 1,
- "sms");
-
gsms = talloc(tall_gsms_ctx, struct gsm_sms);
if (!gsms) {
talloc_free(sms);
@@ -513,3 +505,9 @@
return gsm0411_sendmsg(msg);
}
+
+static __attribute__((constructor)) void on_dso_load_sms(void)
+{
+ tall_sms_ctx = talloc_named_const(tall_bsc_ctx, 1, "sms_submit");
+ tall_gsms_ctx = talloc_named_const(tall_bsc_ctx, 1, "sms");
+}