[MERGED] libosmocore[master]: src/msgb.c: avoid using internal talloc API

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Fri Mar 9 12:04:08 UTC 2018


Harald Welte has submitted this change and it was merged.

Change subject: src/msgb.c: avoid using internal talloc API
......................................................................


src/msgb.c: avoid using internal talloc API

An internal symbol '_talloc_zero' of talloc library was used
during a msgb allocation. This is not actually good because:

  - it may be removed or modified by talloc developers;
  - the behaviour may be changed by talloc developers;
  - it's marked as internal using 'underscore';
  - there is public API to do the same.

So, let's use the public API.

Change-Id: I1080c9071e997944cc0f9fc3716129e9395437ad
---
M src/msgb.c
1 file changed, 4 insertions(+), 2 deletions(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/src/msgb.c b/src/msgb.c
index 82902b4..844cfc6 100644
--- a/src/msgb.c
+++ b/src/msgb.c
@@ -79,14 +79,16 @@
 {
 	struct msgb *msg;
 
-	msg = _talloc_zero(tall_msgb_ctx, sizeof(*msg) + size, name);
-
+	msg = talloc_named_const(tall_msgb_ctx, sizeof(*msg) + size, name);
 	if (!msg) {
 		LOGP(DLGLOBAL, LOGL_FATAL, "Unable to allocate a msgb: "
 			"name='%s', size=%u\n", name, size);
 		return NULL;
 	}
 
+	/* Manually zero-initialize allocated memory */
+	memset(msg, 0x00, sizeof(*msg) + size);
+
 	msg->data_len = size;
 	msg->len = 0;
 	msg->data = msg->_data;

-- 
To view, visit https://gerrit.osmocom.org/7165
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1080c9071e997944cc0f9fc3716129e9395437ad
Gerrit-PatchSet: 2
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list