[PATCH 2/4] tests: avoid PATH_MAX-sized array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



See previous patch for why this is good...

* src/test/test_driver.c (struct _testConn, testOpenFromFile)
(testClose): Manage path dynamically.
---
 src/test/test_driver.c |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6c8b9cf..18f6a52 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -77,7 +77,7 @@ typedef struct _testCell *testCellPtr;
 struct _testConn {
     virMutex lock;

-    char path[PATH_MAX];
+    char *path;
     int nextDomID;
     virCapsPtr caps;
     virNodeInfo nodeInfo;
@@ -790,9 +790,8 @@ static int testOpenFromFile(virConnectPtr conn,

     privconn->nextDomID = 1;
     privconn->numCells = 0;
-    if (virStrcpyStatic(privconn->path, file) == NULL) {
-        testError(VIR_ERR_INTERNAL_ERROR,
-                  _("Path %s too big for destination"), file);
+    if ((privconn->path = strdup(file)) == NULL) {
+        virReportOOMError();
         goto error;
     }
     memmove(&privconn->nodeInfo, &defaultNodeInfo, sizeof(defaultNodeInfo));
@@ -1090,6 +1089,7 @@ static int testOpenFromFile(virConnectPtr conn,
     virNetworkObjListFree(&privconn->networks);
     virInterfaceObjListFree(&privconn->ifaces);
     virStoragePoolObjListFree(&privconn->pools);
+    VIR_FREE(privconn->path);
     testDriverUnlock(privconn);
     VIR_FREE(privconn);
     conn->privateData = NULL;
@@ -1161,6 +1161,7 @@ static int testClose(virConnectPtr conn)
     virInterfaceObjListFree(&privconn->ifaces);
     virStoragePoolObjListFree(&privconn->pools);
     virDomainEventStateFree(privconn->domainEventState);
+    VIR_FREE(privconn->path);

     testDriverUnlock(privconn);
     virMutexDestroy(&privconn->lock);
-- 
1.7.4.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]