/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 plugin-runner.c

Several memory leaks detected by valgrind fixed
A bugg fixed that could cause seg fault.

Show diffs side-by-side

added added

removed removed

Lines of Context:
397
397
      if(arg == NULL){
398
398
        break;
399
399
      }
400
 
      {
401
 
        char *envdef = strdup(arg);
402
 
        if(envdef == NULL){
403
 
          break;
404
 
        }
405
 
        if(not add_environment(getplugin(NULL), envdef, true)){
406
 
          perror("add_environment");
407
 
        }
 
400
      if(not add_environment(getplugin(NULL), arg, true)){
 
401
        perror("add_environment");
408
402
      }
409
403
      break;
410
404
    case 'o':                   /* --options-for */
438
432
        if(envdef == NULL){
439
433
          break;
440
434
        }
441
 
        char *p_name = strndup(arg, (size_t) (envdef-arg));
442
 
        if(p_name == NULL){
443
 
          break;
444
 
        }
445
 
        envdef++;
446
 
        if(not add_environment(getplugin(p_name), envdef, true)){
 
435
        *envdef = '\0';
 
436
        if(not add_environment(getplugin(arg), envdef+1, true)){
447
437
          perror("add_environment");
448
438
        }
449
439
      }
467
457
      }
468
458
      break;
469
459
    case 128:                   /* --plugin-dir */
 
460
      free(plugindir);
470
461
      plugindir = strdup(arg);
471
462
      if(plugindir == NULL){
472
463
        perror("strdup");
510
501
    case 128:                   /* --plugin-dir */
511
502
      break;
512
503
    case 129:                   /* --config-file */
 
504
      free(argfile);
513
505
      argfile = strdup(arg);
514
506
      if(argfile == NULL){
515
507
        perror("strdup");
940
932
    }
941
933
    /* OK, now either a process completed, or something can be read
942
934
       from one of them */
943
 
    for(plugin *proc = plugin_list; proc != NULL; proc = proc->next){
 
935
    for(plugin *proc = plugin_list; proc != NULL;){
944
936
      /* Is this process completely done? */
945
937
      if(proc->eof and proc->completed){
946
938
        /* Only accept the plugin output if it exited cleanly */
973
965
            exitstatus = EXIT_FAILURE;
974
966
            goto fallback;
975
967
          }
976
 
          free_plugin(proc);
 
968
          
977
969
          /* We are done modifying process list, so unblock signal */
978
970
          ret = sigprocmask (SIG_UNBLOCK, &sigchld_action.sa_mask,
979
971
                             NULL);
986
978
          if(plugin_list == NULL){
987
979
            break;
988
980
          }
 
981
          
 
982
          plugin *next_plugin = proc->next;
 
983
          free_plugin(proc);
 
984
          proc = next_plugin;
989
985
          continue;
990
986
        }
991
987
        
1003
999
      /* This process has not completed.  Does it have any output? */
1004
1000
      if(proc->eof or not FD_ISSET(proc->fd, &rfds)){
1005
1001
        /* This process had nothing to say at this time */
 
1002
        proc = proc->next;
1006
1003
        continue;
1007
1004
      }
1008
1005
      /* Before reading, make the process' data buffer large enough */
1021
1018
                 BUFFER_SIZE);
1022
1019
      if(ret < 0){
1023
1020
        /* Read error from this process; ignore the error */
 
1021
        proc = proc->next;
1024
1022
        continue;
1025
1023
      }
1026
1024
      if(ret == 0){