title: EXC_BAD_ACCESS executing block inside another block
body: <p>I'm dealing with some legacy code which calls a chain of blocks inside one other. I randomly hit an <code>EXC_BAD_ACCESS</code> crash from time to time and I can't figure out why. </p>
  
  <pre><code>/
  
  *
       Description: Submit type card transaction to MCM server.
       */
      - (void)submitTypeTransactionWithRequest:(ChargeRequest *)request completion:(void (^)(BOOL))completion {
  
          //login to gateway to begin transaction
          [self loginRoamServerWithCompletion:^(BOOL success) {
              if (success) {
  
                  //make the payment
                  Payment *responsePayment = [self makePayment];
  
                  //if cvv is invalid, decline the transaction
                  [self voidTxnWhenCVV2OrAVSInvalid:responsePayment completion:^(BOOL isValidCVV) {
                      if (completion) {
                          completion(isValidCVV);
                      }
                  }];
              }
          }];
      }
  
      - (void)loginRoamServerWithCompletion:(void (^)(BOOL success))completion {
          ....
  
          [self rpxLogonSuccessfulWithCompletion:^(BOOL success) {
              if (completion) {
                  completion(success);
              }
          }];
      }
  
  - (void)voidTxnWhenCVV2OrAVSInvalid:(RpxPayment *)responsePayment completion:(void (^)(BOOL isValidCVV))completion {
  
          //This method is now called second time in the flow
          [self loginRoamServerWithCompletion:^(BOOL success) {
              if (success) {
                 BOOL result = [self voidPayment];
                 if (completion) {
                    completion(result);
                 }
              }
          }];
      }
      - (void)rpxLogonSuccessfulWithCompletion:(void (^)(BOOL success))completion { 
  
       // at this point, when this method is called the second time =&gt; 'EXC_BAD_ACCESS'(completion = NULL)
  
          BOOL result = [self login]
          if (completion) {
             completion(result);
          }
      }
  </code></pre>
  
  <p>This is how the flow works. The first call is to <code>submitTypeTransactionWithRequest</code>. This then calls <code>loginRoamServerWithCompletion</code> which in turn calls <code>rpxLogonSuccessfulWithCompletion</code>. Once the transaction is done, <code>voidTxnWhenCVV2OrAVSInvalid</code> is called to invalidate the transaction if the CVV is invalid. This in turn calls <code>loginRoamServerWithCompletion</code> again which calls <code>rpxLogonSuccessfulWithCompletion</code>. When, <code>rpxLogonSuccessfulWithCompletion</code> is called for the second time, the code randomly crashes with an <code>EXC_BAD_ACCESS</code> error. The value of the <code>completion</code> block is NULL as per the stack trace.</p>
  
  <p><a href="https://i.stack.imgur.com/4Sron.png" rel="nofollow noreferrer">Attaching the stack trace</a>    </p>