admin管理员组文章数量:1193758
I am trying to learn Vala by writing some app. I faced a memory leak problem which I cannot identify and fix. The app basically iterates through the files in a given directory at a specified interval. Then it executes the executable files from that directory one by one, catching their output and then writing it to a named pipe. If a subprocess takes too long to execute, it cancels it.
I think the problem lies somewhere in the following code snippet (subprocessmunicate_utf8_async ?):
private async bool execute(string file_path, uint timeout_sec, DataOutputStream channel) {
print("Executing %s\n", file_path);
try {
int status = 0;
string output = null;
string errors = null;
Cancellable cancellable = new Cancellable();
Subprocess subprocess = new Subprocess(SubprocessFlags.STDOUT_PIPE | SubprocessFlags.STDERR_PIPE, file_path);
uint timeout_id = Timeout.add_seconds(timeout_sec, () => {
print("Cancelling subprocess...\n");
cancellable.cancel();
subprocess.force_exit();
return Source.REMOVE;
}, Priority.LOW);
try {
yield subprocessmunicate_utf8_async(null, cancellable, out output, out errors);
status = subprocess.get_exit_status();
if (subprocess.get_successful() && output != null) {
print("OUT:\n%s", output);
string[] lines = output.split("\n" );
write_to_channel(channel, lines);
} else {
stderr.printf("Subprocess returned code %d with errors: %s\n", status, errors);
return false;
}
return true;
} catch (IOError.CANCELLED e) {
stderr.printf("Subprocess was cancelled.\n");
} finally {
if (!cancellable.is_cancelled()) {
Source.remove(timeout_id);
}
subprocess.dispose();
}
} catch (Error e) {
stderr.printf("Subprocess execution error: %s\n", e.message);
}
return false;
}
Does anyone see what is wrong here? Also, any pieces of advice with regards to the idiomatic way of doing such things in Vala would be much appreciated
本文标签: Memory leak when using Subprocess in ValaStack Overflow
版权声明:本文标题:Memory leak when using Subprocess in Vala - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738414500a2085509.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论