A memory leak in SecCodeCopySigningInformation or SecCodeCheckValidity?

Hi Experts,

I created a simple application with the following code to retrieve the signing info from Apps such as Xcode:


  CFURLRef appURLRef = NULL;
  SecStaticCodeRef staticCodeRef = NULL;
  CFDictionaryRef signatureInfoRef = NULL;
   
  do {
    appURLRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR("/Applications/Xcode.app"), kCFURLPOSIXPathStyle, YES);
    if(!appURLRef) {
      break;
    }
     
    OSStatus status = SecStaticCodeCreateWithPath(appURLRef, kSecCSDefaultFlags, &staticCodeRef);
    if(errSecSuccess != status) {
      break;
    }
     
    status = SecCodeCopySigningInformation(staticCodeRef, kSecCSSigningInformation, &signatureInfoRef);
    if(errSecSuccess != status) {
      break;
    }
  } while(0);
   
  if(staticCodeRef) {
    CFRelease(staticCodeRef);
    staticCodeRef = NULL;
  }
  if(signatureInfoRef) {
    CFRelease(signatureInfoRef);
    signatureInfoRef = NULL;
  }
  if(appURLRef) {
    CFRelease(appURLRef);
    appURLRef = NULL;
  }

then I use leaks to check if any memory issues, the output is:

Process:         checksig [4733]
Path:            /Users/USER/Library/Developer/Xcode/DerivedData/Build/Products/Debug/checksig
Load Address:    0x10e033000
Identifier:      checksig
Version:         ???
Code Type:       X86-64
Platform:        macOS
Parent Process:  leaks [4732]

Date/Time:       2022-02-13 23:10:32.606 +0800
Launch Time:     2022-02-13 23:10:32.109 +0800
OS Version:      Mac OS X 10.15.6 (19G73)
Report Version:  7
Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/leaks
Analysis Tool Version:  Xcode 12.4 (12D4e)
----

leaks Report Version: 4.0
Process 4733: 3725 nodes malloced for 456 KB
Process 4733: 1 leak for 32 total leaked bytes.

    1 (32 bytes) ROOT LEAK: 0x7ffc33d04c00 [32]  length: 23  ",CSSMERR_CL_UNKNOWN_TAG"

If I remove the SecCodeCopySigningInformation line, then the issue is gone.

So there is a memory leak in API SecCodeCopySigningInformation? or in my code or sth incorrect in the report of leaks? Did anybody see the same issue before? thanks a lot!

Accepted Reply

So there is a memory leak in API SecCodeCopySigningInformation?

It certainly looks that way.

If it reproduces on the latest macOS release, I encourage you to file a bug about it. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Thanks a lot, @eskimo. The issue was found on macOS 10.15, let me test it on the latest macOS.

Add a Comment

Replies

So there is a memory leak in API SecCodeCopySigningInformation?

It certainly looks that way.

If it reproduces on the latest macOS release, I encourage you to file a bug about it. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • Thanks a lot, @eskimo. The issue was found on macOS 10.15, let me test it on the latest macOS.

Add a Comment

Hi @eskimo, I verified this issue can not be reproduced on 12.0.1. Looks Apple fixed it:)

  • Yay for us!

Add a Comment