Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4274322
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:49:53+00:00 2026-05-21T07:49:53+00:00

I’m new on objc/Cocoa and I never use C before. I’ve a problem to

  • 0

I’m new on objc/Cocoa and I never use C before.

I’ve a problem to get previously defined C struct data…
Here’s my code :

AppController.h

#import <Cocoa/Cocoa.h>

@interface AppController : NSObject {
    AuthorizationRef authRef;
    AuthorizationRights authRights;
    AuthorizationFlags authFlags;
}
- (IBAction)toggleAuthentification:(id)sender;
@end

AppController.m

#import "AppController.h"

@implementation AppController
    - (id)init {
        if (![super init])
            return nil;

        AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authRef);
        AuthorizationItem rightItems[1] = {{"com.myname.myapp.adminRights", 0, NULL, 0}};
        authRights.count = 1;
        authRights.items = rightItems;
        authFlags = kAuthorizationFlagDefaults | kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize;

        return self;
    }

    - (IBAction)toggleAuthentification:(id)sender {
        NSLog(@"%d", AuthorizationCopyRights(authRef, &authRights, kAuthorizationEmptyEnvironment, authFlags ^ kAuthorizationFlagInteractionAllowed, NULL));
    }
@end

When I click on a button in my app that call toggleAuthentification:, I get error code -60008 (errAuthorizationInternal).
In the debugger I can see authRights.count = 1, that correct, but authRights.items do not correspond in any way to data defined in init.

I try many different way but I don’t find solution.

Please, anyone can explain why it doesn’t work like I would it work and how to resolve my problem.

Bil

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:49:53+00:00Added an answer on May 21, 2026 at 7:49 am

    The problem in your code is memory management.

    When you create rightItems[], an array of AuthorizationItem elements, it is created in the stack since rightItems[] is an automatic (local) variable. This means that the memory used by the array is deallocated at the end of the method. Since you’re assigning rightItems[] to authRights.items, authRights.items points to a bogus memory address after -init has finished executing. Any further reference to authRights.items has undefined behaviour and is likely to produce an error in your program.

    What you need to do is to create the array in the heap so that it isn’t deallocated when -init has finished executing. You can do that via malloc(). For instance:

    const size_t numberOfRightItems = 1;
    AuthorizationItem *rightItems = malloc(sizeof(AuthorizationItem)
        * numberOfRightItems);
    rightItems[0] = (AuthorizationItem){"com.myname.myapp.adminRights", 0, NULL, 0};
    
    authRights.items = rightItems;
    

    In theory, you’re responsible for releasing authRights.items when it’s not needed any longer since you’ve allocated memory for it in the heap. Hence, in your -dealloc method:

    - (void)dealloc {
        free(authRights.items);
        super[dealloc];
    }
    

    I’ve said in theory because you’re storing the authorisation rights in your application controller. Since the application controller lives throughout the application lifecycle, technically it won’t receive -release or -dealloc. However, it’s good practice and potentially useful in case you rearchitect your application and that code ends up being in a class whose objects are not necessarily alive until the application exits.

    One further note: you should assign the return value of [super init] to self in your -init method. This is also good practice since it is possible that [super init] returns a different object than current self.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.