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

  • SEARCH
  • Home
  • 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 8732773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:30:01+00:00 2026-06-13T09:30:01+00:00

void EventCloseServer::act(){ Server* serv = Program()::getServer(); if (serv != NULL) { if (serv->running()) {

  • 0
void EventCloseServer::act(){
    Server* serv = Program()::getServer();
    if (serv != NULL) {
        if (serv->running()) {
            serv->stop();
            serv->sync();
        }
        delete (serv);
    }
}

The problem arises when I execute this code twice. The first time, the function gets to delete(serv) alright. The second time, it causes segmentation fault before the call to serv->running() and after serv != NULL.
I don’t understand why the second execution gets inside the first if statement. Isn’t it true that the following will result in myObject = NULL?

Class* myObject = new Class();
/***/
delete(myObject); /* myObject = NULL ? */
  • 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-06-13T09:30:02+00:00Added an answer on June 13, 2026 at 9:30 am

    No, it is not true.
    delete does not set pointer to NULL. It merely deallocates the memory allocated to the pointer and calls appropriate destructors.

    On other hand calling delete on a NULL pointer is a No-Op. So it is not required to check for NULL before calling delete.

    Note that explicitly NULLing the pointer after delete shall seem to solve your problem but it might hide problems in your code.The best way to solve this is to use Smart pointers and not raw pointers which need explicit memory management.

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

Sidebar

Related Questions

void SaveFiles(out XElement Attachments) { Attachments = null; if (Uploader1.UploadedFiles.Count() > 0) { Attachments
void getS(char *fileName){ FILE *src; if((src = fopen(fileName, r)) == NULL){ printf(%s %s %s,
void currentfor() { if(current == NULL) { cout << You don't have any members
void getThisAlert(String Title, Displayable txtagency2) { Alert error = new Alert(, Title, null, AlertType.INFO);
- (void)viewDidLoad{ [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@VidName ofType:@mov]; NSURL *url =
void test() { unsigned char c; c = (~0)>>1 ; printf(c is %u\n,c); }
- (void)TargetHit:(int)target{ void (^threadBlock)(void) = ^{ NSLog(@respond to selector %d, [self respondsToSelector:@selector(changeImageOfTarget:)]); [[NSOperationQueue mainQueue]
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { self.listFeedConnection = nil; // release our connection [UIApplication sharedApplication].networkActivityIndicatorVisible =
- (void)fadeOutSplash { UIImageView *splash = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@Default-Landscape~ipad.png]]; [self.window.rootViewController.view addSubview:splash]; // <--
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif { // Handle the notificaton when the app is

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.