title: Segmentation fault while testing with google test
body: <p>I am passing a compound structure pointer to a function after doing all the memory initializations in a test fixture. But as soon as the function gets called the sizeof that struct changes.
  Have tried setting watchpoints and  everything. don't the what's the issue.
  Need help.
  This is the code for the test.</p>
  
  <p>sizeof(*ueCb) changes just after calling the function cwRrcSendMibCfgReq.
  The function is copying some parameters from ueCb. ueCb has multiple structures inside of it. Accessing ueCb->currContestCellForSel in the function throws a segmentation fault even though I have explicitly allocated memory here. I have checked that the allocation occurs. I check sizeof(*ueCb) in gdb keeping the mentioned fucntion as a breakpoint. The header files are the same. Also ueId remains intact while calling the function. CW_ALLOC is an internal macro which allocates memory. it's working fine I have checked that.</p>
  
  <p>Can't share the whole code because it's part of IP. This code is related to 5G protocol stack.My job is to do unit testing and the entire team isn't able to figure out where the problem is.</p>
  
  <pre><code>TEST(testMib1, test)
  {
  
      CwRrcUeCb* ueCb;
      CW_ALLOC(CW_REG,CW_POOL,&amp;ueCb, sizeof(CwRrcUeCb));
      memset(ueCb, 0, sizeof(CwRrcUeCb));
      ueCb-&gt;currContestCellForSel = (CwRrcCellCb *) 
      malloc(sizeof(CwRrcCellCb));
      ueCb-&gt;currContestCellForSel-&gt;phyCellId = 5;
      ueCb-&gt;ueId = 5;
      S16 ret = ROK;
  
      ret = cwRrcSendMibCfgReq(ueCb); // sizeof *ueCb changes after this statement
      free(ueCb-&gt;currContestCellForSel);        
      CW_FREE(CW_REG, CW_POOL, ueCb, sizeof (CwRrcUeCb));
  
      // have changed the order just to get to the main point
      EXPECT_EQ(ROK, ret);
      printf(" Event 9 Done\n\n\n");
  }
  </code></pre>
  
  <p>The backtrace is as follows:</p>
  
  <pre><code>(gdb) backtrace
  #0  0x000000000053a673 in cwRrcSendMibCfgReq (rrcUeCb=0x7ffff5d45320) at ../src/5gnrueapp/cw_rrc_fsm.c:2745
  #1  0x000000000061dd59 in testMib1_test_Test::TestBody (this=0xa73500) at ../unittest/test_Event9Mib1.cc:79
  #2  0x00007ffff71847a3 in void testing::internal::HandleExceptionsInMethodIfSupported&lt;testing::Test, void&gt;(testing::Test*, void (testing:
  :Test::*)(), char const*) () from /lib64/libgtest.so.0
  #3  0x00007ffff717ab27 in testing::Test::Run() () from /lib64/libgtest.so.0
  #4  0x00007ffff717abce in testing::TestInfo::Run() () from /lib64/libgtest.so.0
  #5  0x00007ffff717acd5 in testing::TestCase::Run() () from /lib64/libgtest.so.0
  #6  0x00007ffff717e018 in testing::internal::UnitTestImpl::RunAllTests() () from /lib64/libgtest.so.0
  #7  0x00007ffff717e2a7 in testing::UnitTest::Run() () from /lib64/libgtest.so.0
  #8  0x000000000061e156 in main (argc=1, argv=0x7fffffffe1d8) at ../unittest/test_main.cc:38
  </code></pre>
  
  <p>the function which I'm testing</p>
  
  <pre><code>S16 cwRrcSendMibCfgReq(CwRrcUeCb * rrcUeCb)
  {
     CtzMibConfigRequest *mibConfig = NULLP;
  
     CW_ALLOC(CW_REG, CW_POOL, &amp;mibConfig, sizeof (CtzMibConfigRequest));
  
     if(NULL == mibConfig)
     {
        RLOG1(L_FATAL,"Memory Allocation Failed while sending Mib config req ueId:%d",rrcUeCb-&gt;ueId);
        RETVALUE(RFAILED);
     }
  
     mibConfig-&gt;pres.pres = 1;
     mibConfig-&gt;systemFrameNumber       = rrcUeCb-&gt;cwMibInfo.systemFrameNumber;
     mibConfig-&gt;subCarrierSpacingCommon = rrcUeCb-&gt;cwMibInfo.subCarrierSpacingCommon;
     mibConfig-&gt;ssb_SubcarrierOffset    = rrcUeCb-&gt;cwMibInfo.ssb_SubcarrierOffset;
     mibConfig-&gt;dmrs_TypeAPosition      = rrcUeCb-&gt;cwMibInfo.dmrs_TypeAPosition;
     mibConfig-&gt;pdcch_ConfigSIB1.controlResourceSetZero =
        rrcUeCb-&gt;cwMibInfo.pdcch_ConfigSIB1.controlResourceSetZero;
     mibConfig-&gt;pdcch_ConfigSIB1.searchSpaceZero        = rrcUeCb-&gt;cwMibInfo.pdcch_ConfigSIB1.searchSpaceZero;
  
     mibConfig-&gt;ueId                    =  rrcUeCb-&gt;ueId;
     mibConfig-&gt;cellId                  =  rrcUeCb-&gt;currContestCellForSel-&gt;phyCellId;
     RLOG0(L_DEBUG,"[CFGREQ] [SRC:RRC    ==&gt;&gt; DST:CL(PHY)]   : CTZ_CPHY_MIB_CFG_REQ");
     printf("\n[SRC:RRC    ==&gt;&gt; DST:CL(PHY)]   : CTZ_CPHY_MIB_CFG_REQ\n");
     CwLiCtzCfgReq(&amp;cwCb.ctzSapCbLst[0]-&gt;pst,CTZ_CPHY_MIB_CFG_REQ, mibConfig);
  
     RETVALUE(ROK);
  }
  </code></pre>