]> xenbits.xensource.com Git - libvirt.git/commitdiff
virStorageVol: avoid PATH_MAX-sized array
authorEric Blake <eblake@redhat.com>
Wed, 22 Jun 2011 19:51:32 +0000 (13:51 -0600)
committerEric Blake <eblake@redhat.com>
Wed, 22 Jun 2011 23:13:58 +0000 (17:13 -0600)
POSIX allows implementations where PATH_MAX is undefined, leading
to compilation error.  Not to mention that even if it is defined,
it is often wasteful in relation to the amount of data being stored.

All clients of vol->key were audited, and found not to care about
whether key is static or dynamic, except for these offenders:

* src/datatypes.h (struct _virStorageVol): Manage key dynamically.
* src/datatypes.c (virReleaseStorageVol): Free key.
(virGetStorageVol): Copy key.

src/datatypes.c
src/datatypes.h

index 4c4cbd02393d90c6d6ffb10b0189efa9e6679179..f0b50259f9c3f12afdc514ea4108e321332a7eb3 100644 (file)
@@ -738,10 +738,10 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
         virReportOOMError();
         goto error;
     }
-    if (virStrcpyStatic(ret->key, key) == NULL) {
+    ret->key = strdup(key);
+    if (ret->key == NULL) {
         virMutexUnlock(&conn->lock);
-        virLibConnError(VIR_ERR_INTERNAL_ERROR,
-                        _("Volume key %s too large for destination"), key);
+        virReportOOMError();
         goto error;
     }
     ret->magic = VIR_STORAGE_VOL_MAGIC;
@@ -754,6 +754,7 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name,
 
 error:
     if (ret != NULL) {
+        VIR_FREE(ret->key);
         VIR_FREE(ret->name);
         VIR_FREE(ret->pool);
         VIR_FREE(ret);
@@ -780,6 +781,7 @@ virReleaseStorageVol(virStorageVolPtr vol) {
     VIR_DEBUG("release vol %p %s", vol, vol->name);
 
     vol->magic = -1;
+    VIR_FREE(vol->key);
     VIR_FREE(vol->name);
     VIR_FREE(vol->pool);
     VIR_FREE(vol);
index ebda9928cd2f4d38b12a879cd7d1fd5410777077..f114360b51183a57d9bfc359a0891e76777f512f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * datatypes.h: management of structs for public data types
  *
- * Copyright (C) 2006-2008, 2010 Red Hat, Inc.
+ * Copyright (C) 2006-2008, 2010-2011 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -254,8 +254,7 @@ struct _virStorageVol {
     virConnectPtr conn;                  /* pointer back to the connection */
     char *pool;                          /* Pool name of owner */
     char *name;                          /* the storage vol external name */
-    /* XXX currently abusing path for this. Ought not to be so evil */
-    char key[PATH_MAX];                  /* unique key for storage vol */
+    char *key;                           /* unique key for storage vol */
 };
 
 /**