diff --git a/obexd/plugins/filesystem.c b/obexd/plugins/filesystem.c
index f0e5bbe..bf00ac2 100644
--- a/obexd/plugins/filesystem.c
+++ b/obexd/plugins/filesystem.c
int pid;
int output;
int err;
- unsigned int watch;
+ gboolean aborted;
GString *buffer;
};
char buf[128];
object->pid = -1;
- object->watch = 0;
DBG("pid: %d status: %d", pid, status);
+ g_spawn_close_pid(pid);
+
+ /* free the object if aborted */
+ if (object->aborted) {
+ if (object->buffer != NULL)
+ g_string_free(object->buffer, TRUE);
+
+ g_free(object);
+ return;
+ }
+
if (WEXITSTATUS(status) != EXIT_SUCCESS) {
memset(buf, 0, sizeof(buf));
if (read(object->err, buf, sizeof(buf)) > 0)
obex_object_set_io_flags(data, G_IO_ERR, -EPERM);
} else
obex_object_set_io_flags(data, G_IO_IN, 0);
-
- g_spawn_close_pid(pid);
}
static int capability_exec(const char **argv, int *output, int *err)
if (object->pid < 0)
goto fail;
- object->watch = g_child_watch_add(object->pid, script_exited, object);
+ /* Watch cannot be removed while the process is still running */
+ g_child_watch_add(object->pid, script_exited, object);
done:
if (err)
if (obj->pid < 0)
goto done;
- if (obj->watch)
- g_source_remove(obj->watch);
-
- g_spawn_close_pid(obj->pid);
-
DBG("kill: pid %d", obj->pid);
err = kill(obj->pid, SIGTERM);
if (err < 0) {
err = -errno;
error("kill: %s (%d)", strerror(-err), -err);
+ goto done;
}
+ obj->aborted = TRUE;
+ return 0;
+
done:
if (obj->buffer != NULL)
g_string_free(obj->buffer, TRUE);