Archive for the ‘memory leakage’ Category

kernel: patch: memory leakage: single_open

August 10, 2015

In linux-kernel, Al Viro contributes several patches with title single_open() leaks. This post is to discuss memory leakage related to single_open.

single_open itself doesn’t cause memory leakage. The root cause of memory leakage is asymmetric open/release of a file structure. If a file’s open is single_open and its release is seq_release, then seq_file->op is not freed and leaked.

seq_open:              alloc seq_file, seq->buf
single_open:           alloc seq_file, seq->buf, seq_file->op
seq_open_private:      alloc seq_file, seq->buf, seq_file->private
seq_release:         release seq_file, seq->buf
single_release:      release seq_file, seq->buf, seq_file->op
seq_release_private: release seq_file, seq->buf, seq_file->private


In conclusion, to avoid memory leakage, open/release a sequential file with symmetric functions.

  • seq_open v.s seq_release
  • single_open v.s. single_release
  • seq_open_private v.s. seq_open_release

  • %d bloggers like this: