<p>Turns out the <code>pragma</code> fix was just co-incidental.<br>
I did a couple of other tests.<br>
This time I printed the complete memory mapping as follows in <code>cfg_clone_global</code>:</p>
<pre><code>LOG(L_ERR,"START");
LOG(L_ERR,"block address: %p",(void *)block);
LOG(L_ERR,"vars address: %p",(void *)(block->vars));
LOG(L_ERR,"Total allocated size: %d",(sizeof(cfg_block_t)+cfg_block_size-1));
int count = 0;
for (group = cfg_group;
        group;
        group=group->next
){
        count = count + 1;
        LOG(L_ERR,"Group number: %d", count);
        LOG(L_ERR,"Group location from start %d",(int)(((void *)(CFG_GROUP_DATA(block, group)))-((void *)block)));
        LOG(L_ERR,"Group size: %d", group->size);
}
</code></pre>
<p>I did two tests:<br>
Test 1: With pragma block around cfg_block_t only<br>
Test 2: With the complete patch applied</p>
<p>Test1 output:</p>
<pre><code>Memory mapping (with pragma for cfg_block_t)
============================================

(Error persists and variables takes random values)

## All the locations below assume that the address starts at 0

START
block address: 0x7f6c37550d98
vars address: 0x7f6c37550d9c
Total allocated size: 1160
Group number: 1
Group location from start 20
Group size: 248
Group number: 2
Group location from start 284
Group size: 56
Group number: 3
Group location from start 356
Group size: 4
Group number: 4
Group location from start 380
Group size: 4
Group number: 5
Group location from start 404
Group size: 4
Group number: 6
Group location from start 428
Group size: 176
Group number: 7
Group location from start 620
Group size: 104
Group number: 8
Group location from start 740
Group size: 200
Group number: 9
Group location from start 956
Group size: 16
Group number: 10
Group location from start 988
Group size: 172

## still one extra byte
</code></pre>
<p>As you can see 988+172=1160 but the address is starting from 0 here so we should have assigned 1161 bytes of memory.</p>
<p>Test2 output:</p>
<pre><code>Memory mapping (with the complete patch applied)
================================================

(Error persists and variables takes random values)

## All the locations below assume that the address starts at 0

START
block address: 0x7fc1537af4b8
vars address: 0x7fc1537af4bc
Total allocated size: 1160
Group number: 1
Group location from start 20
Group size: 248
Group number: 2
Group location from start 284
Group size: 56
Group number: 3
Group location from start 356
Group size: 4
Group number: 4
Group location from start 380
Group size: 4
Group number: 5
Group location from start 404
Group size: 4
Group number: 6
Group location from start 428
Group size: 176
Group number: 7
Group location from start 620
Group size: 104
Group number: 8
Group location from start 740
Group size: 200
Group number: 9
Group location from start 956
Group size: 16
Group number: 10
Group location from start 988
Group size: 172

## still one extra byte
</code></pre>
<p>Not sure why the first group starts from location 20 but I can say with confidence that using <code>pragma</code> blocks doesn't solve this issue.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/1583#issuecomment-403626150">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AF36ZdEZ0feEMXSkwCJCFK8W2LTh5N0Aks5uE8rmgaJpZM4VDDlj">mute the thread</a>.<img src="https://github.com/notifications/beacon/AF36ZVpehGSCFzRCytizS_VE5Y3XA0IMks5uE8rmgaJpZM4VDDlj.gif" height="1" width="1" alt="" /></p>
<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/kamailio/kamailio","title":"kamailio/kamailio","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/kamailio/kamailio"}},"updates":{"snippets":[{"icon":"PERSON","message":"@vinesinha in #1583: Turns out the `pragma` fix was just co-incidental. \r\nI did a couple of other tests. \r\nThis time I printed the complete memory mapping as follows in `cfg_clone_global`:\r\n\r\n```\r\nLOG(L_ERR,\"START\");\r\nLOG(L_ERR,\"block address: %p\",(void *)block);\r\nLOG(L_ERR,\"vars address: %p\",(void *)(block-\u003evars));\r\nLOG(L_ERR,\"Total allocated size: %d\",(sizeof(cfg_block_t)+cfg_block_size-1));\r\nint count = 0;\r\nfor (group = cfg_group;\r\n\tgroup;\r\n\tgroup=group-\u003enext\r\n){\r\n\tcount = count + 1;\r\n\tLOG(L_ERR,\"Group number: %d\", count);\r\n\tLOG(L_ERR,\"Group location from start %d\",(int)(((void *)(CFG_GROUP_DATA(block, group)))-((void *)block)));\r\n\tLOG(L_ERR,\"Group size: %d\", group-\u003esize);\r\n}\r\n```\r\n\r\nI did two tests:\r\nTest 1: With pragma block around cfg_block_t only\r\nTest 2: With the complete patch applied \r\n\r\nTest1 output:\r\n\r\n```\r\nMemory mapping (with pragma for cfg_block_t)\r\n============================================\r\n\r\n(Error persists and variables takes random values)\r\n\r\n## All the locations below assume that the address starts at 0\r\n\r\nSTART\r\nblock address: 0x7f6c37550d98\r\nvars address: 0x7f6c37550d9c\r\nTotal allocated size: 1160\r\nGroup number: 1\r\nGroup location from start 20\r\nGroup size: 248\r\nGroup number: 2\r\nGroup location from start 284\r\nGroup size: 56\r\nGroup number: 3\r\nGroup location from start 356\r\nGroup size: 4\r\nGroup number: 4\r\nGroup location from start 380\r\nGroup size: 4\r\nGroup number: 5\r\nGroup location from start 404\r\nGroup size: 4\r\nGroup number: 6\r\nGroup location from start 428\r\nGroup size: 176\r\nGroup number: 7\r\nGroup location from start 620\r\nGroup size: 104\r\nGroup number: 8\r\nGroup location from start 740\r\nGroup size: 200\r\nGroup number: 9\r\nGroup location from start 956\r\nGroup size: 16\r\nGroup number: 10\r\nGroup location from start 988\r\nGroup size: 172\r\n\r\n## still one extra byte\r\n```\r\n\r\nAs you can see 988+172=1160 but the address is starting from 0 here so we should have assigned 1161 bytes of memory.\r\n\r\nTest2 output:\r\n\r\n```\r\nMemory mapping (with the complete patch applied)\r\n================================================\r\n\r\n(Error persists and variables takes random values)\r\n\r\n## All the locations below assume that the address starts at 0\r\n\r\nSTART\r\nblock address: 0x7fc1537af4b8\r\nvars address: 0x7fc1537af4bc\r\nTotal allocated size: 1160\r\nGroup number: 1\r\nGroup location from start 20\r\nGroup size: 248\r\nGroup number: 2\r\nGroup location from start 284\r\nGroup size: 56\r\nGroup number: 3\r\nGroup location from start 356\r\nGroup size: 4\r\nGroup number: 4\r\nGroup location from start 380\r\nGroup size: 4\r\nGroup number: 5\r\nGroup location from start 404\r\nGroup size: 4\r\nGroup number: 6\r\nGroup location from start 428\r\nGroup size: 176\r\nGroup number: 7\r\nGroup location from start 620\r\nGroup size: 104\r\nGroup number: 8\r\nGroup location from start 740\r\nGroup size: 200\r\nGroup number: 9\r\nGroup location from start 956\r\nGroup size: 16\r\nGroup number: 10\r\nGroup location from start 988\r\nGroup size: 172\r\n\r\n## still one extra byte\r\n```\r\n\r\nNot sure why the first group starts from location 20 but I can say with confidence that using `pragma` blocks doesn't solve this issue. "}],"action":{"name":"View Issue","url":"https://github.com/kamailio/kamailio/issues/1583#issuecomment-403626150"}}}</script>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/1583#issuecomment-403626150",
"url": "https://github.com/kamailio/kamailio/issues/1583#issuecomment-403626150",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
},
{
"@type": "MessageCard",
"@context": "http://schema.org/extensions",
"hideOriginalBody": "false",
"originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB",
"title": "Re: [kamailio/kamailio] cfg_rpc updates changing variable values to large random numbers  (#1583)",
"sections": [
{
"text": "",
"activityTitle": "**vinesinha**",
"activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png",
"activitySubtitle": "@vinesinha",
"facts": [

]
}
],
"potentialAction": [
{
"name": "Add a comment",
"@type": "ActionCard",
"inputs": [
{
"isMultiLine": true,
"@type": "TextInput",
"id": "IssueComment",
"isRequired": false
}
],
"actions": [
{
"name": "Comment",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1583,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}"
}
]
},
{
"name": "Close issue",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"kamailio/kamailio\",\n\"issueId\": 1583\n}"
},
{
"targets": [
{
"os": "default",
"uri": "https://github.com/kamailio/kamailio/issues/1583#issuecomment-403626150"
}
],
"@type": "OpenUri",
"name": "View on GitHub"
},
{
"name": "Unsubscribe",
"@type": "HttpPOST",
"target": "https://api.github.com",
"body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 353122659\n}"
}
],
"themeColor": "26292E"
}
]</script>