/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/plymouth.c

  • Committer: Teddy Hogeborn
  • Date: 2017-09-03 08:26:36 UTC
  • Revision ID: teddy@recompile.se-20170903082636-fo3qw1uoahjxw0by
Fix memory leak in plymouth plugin

* plugins.d/plymouth.c (getargv): Change return type to non-const.
  (main/plymouth_args): Change type to non-const and default to NULL.
  (main): Don't change plymouthd_argv, instead conditionally use it if
  it is allocated or use plymouthd_default_argv if not.
  (main): Free plymouthd_argv, if allocated.

Show diffs side-by-side

added added

removed removed

Lines of Context:
317
317
  return 0;
318
318
}
319
319
 
320
 
const char * const * getargv(pid_t pid){
 
320
char **getargv(pid_t pid){
321
321
  int cl_fd;
322
322
  char *cmdline_filename;
323
323
  ssize_t sret;
384
384
    return NULL;
385
385
  }
386
386
  argz_extract(cmdline, cmdline_len, argv); /* Create argv */
387
 
  return (const char * const *)argv;
 
387
  return argv;
388
388
}
389
389
 
390
390
int main(__attribute__((unused))int argc,
465
465
  }
466
466
  kill_and_wait(plymouth_command_pid);
467
467
  
468
 
  const char * const *plymouthd_argv;
 
468
  char **plymouthd_argv = NULL;
469
469
  pid_t pid = get_pid();
470
470
  if(pid == 0){
471
471
    error_plus(0, 0, "plymouthd pid not found");
472
 
    plymouthd_argv = plymouthd_default_argv;
473
472
  } else {
474
473
    plymouthd_argv = getargv(pid);
475
474
  }
478
477
                       { plymouth_path, "quit", NULL },
479
478
                       false, false);
480
479
  if(not bret){
 
480
    if(plymouthd_argv != NULL){
 
481
      free(*plymouthd_argv);
 
482
      free(plymouthd_argv);
 
483
    }
481
484
    exit(EXIT_FAILURE);
482
485
  }
483
 
  bret = exec_and_wait(NULL, plymouthd_path, plymouthd_argv,
 
486
  bret = exec_and_wait(NULL, plymouthd_path,
 
487
                       (plymouthd_argv != NULL)
 
488
                       ? (const char * const *)plymouthd_argv
 
489
                       : plymouthd_default_argv,
484
490
                       false, true);
 
491
  if(plymouthd_argv != NULL){
 
492
    free(*plymouthd_argv);
 
493
    free(plymouthd_argv);
 
494
  }
485
495
  if(not bret){
486
496
    exit(EXIT_FAILURE);
487
497
  }