Branch: Tag:

2019-06-25

2019-06-25 14:17:54 by Stephen R. van den Berg <srb@cuci.nl>

Shuffler: Shuffle objects can disappear before source objects.

This makes the callback argument passed to source objects that need
callbacks a counted object, so that it will not disappear while
the source object is still trying to run the callback after the
Shuffle object has already vanished.

40:    int eof;       void (*when_data_cb)( void *a ); -  void *when_data_cb_arg; +  struct object *when_data_cb_arg;    size_t len, skip;   };   
134:    s->str = 0;    }    pop_n_elems(args); - cb: if( s->when_data_cb ) -  s->when_data_cb( s->when_data_cb_arg ); + cb: if (s->when_data_cb) +  s->when_data_cb(s->when_data_cb_arg);    }       push_int(0);   }    - static void set_callback( struct source *src, void (*cb)( void *a ), void *a ) - { + static void +  set_callback(struct source *src, void (*cb)( void *a ), struct object *a) {    struct pf_source *s = (struct pf_source *)src;    s->when_data_cb = cb; -  s->when_data_cb_arg = a; +  if (!s->when_data_cb_arg) +  add_ref(s->when_data_cb_arg = a);   }      static void free_source( struct source *src ) {
186:    remove_callbacks((struct source*)THIS);    free_object(THIS->obj);    THIS->obj = 0; +  if (THIS->when_data_cb_arg) +  free_object(THIS->when_data_cb_arg);   }      void source_pikestream_exit() {