Skip to content

Commit

Permalink
drives: Add comments about fragile string handling.
Browse files Browse the repository at this point in the history
GC FTW.
  • Loading branch information
rwmjones committed Aug 19, 2014
1 parent b53286a commit 0fd95e2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/drives.c
Expand Up @@ -676,6 +676,11 @@ parse_one_server (guestfs_h *g, const char *server, struct drive_server *ret)
char *port_str;
int port;

/* Note! Do not set any string field in *ret until you know the
* function will return successfully. Otherwise there can be a
* double-free in parse_servers -> free_drive_servers below.
*/

ret->transport = drive_transport_none;

if (STRPREFIX (server, "tcp:")) {
Expand Down Expand Up @@ -739,6 +744,9 @@ parse_servers (guestfs_h *g, char *const *strs,
return 0;
}

/* Must use calloc here to avoid freeing garbage along the error
* path below.
*/
servers = safe_calloc (g, n, sizeof (struct drive_server));

for (i = 0; i < n; ++i) {
Expand Down

0 comments on commit 0fd95e2

Please sign in to comment.