On Monday 15 June 2015 11:49:35 Chen Hanxiao wrote:
We should not use tmp lines buffer as return value, for lines buffer will be freed.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- v3: don't return internal tmp values.
daemon/btrfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/daemon/btrfs.c b/daemon/btrfs.c index 39392f7..5011ec4 100644 --- a/daemon/btrfs.c +++ b/daemon/btrfs.c @@ -1254,7 +1254,7 @@ do_btrfs_qgroup_show (const char *path) CLEANUP_FREE char *err = NULL; CLEANUP_FREE char *out = NULL; int r; - char **lines; + CLEANUP_FREE_STRING_LIST char **lines = NULL;
path_buf = sysroot_path (path); if (path_buf == NULL) { @@ -1320,14 +1320,14 @@ do_btrfs_qgroup_show (const char *path)
The full code here is: if (sscanf (line, "%" SCNu64 "/%" SCNu64 " %" SCNu64 " %" SCNu64, &dummy1, &dummy2, &this->btrfsqgroup_rfer, &this->btrfsqgroup_excl) != 4) { reply_with_error ("cannot parse output of qgroup show command: %s", line); goto error; } p = strchr(line, ' '); if (!p) { reply_with_error ("truncated line: %s", line); goto error; }
*p = '\0'; - this->btrfsqgroup_id = line; + this->btrfsqgroup_id = strdup (line); + if (this->btrfsqgroup_id == NULL) + goto error; }
I'd say that sscanf + character class + allocation should be able to extract the string of the qgroup id, so there's no need to change 'line' nor to manually duplicate part of the string. Something like: sscanf (line, "%m[0-9/] %" SCNu64 " %" SCNu64, &this->btrfsqgroup_id, &this->btrfsqgroup_rfer, &this->btrfsqgroup_excl) Thanks, -- Pino Toscano