system-config-printer/system-config-printer-cupsconnection-dealloc.patch
2010-03-08 17:04:23 +00:00

70 lines
1.7 KiB
Diff

diff -up system-config-printer-1.1.17/pycups-1.9.48/cupsconnection.c.cupsconnection-dealloc system-config-printer-1.1.17/pycups-1.9.48/cupsconnection.c
--- system-config-printer-1.1.17/pycups-1.9.48/cupsconnection.c.cupsconnection-dealloc 2010-03-08 17:06:47.000000000 +0100
+++ system-config-printer-1.1.17/pycups-1.9.48/cupsconnection.c 2010-03-08 17:06:47.000000000 +0100
@@ -231,37 +231,43 @@ Connection_dealloc (Connection *self)
{
int i, j;
- if (NumConnections > 1)
- {
- Connection **new_array = calloc (NumConnections - 1,
- sizeof (Connection *));
+ for (j = 0; j < NumConnections; j++)
+ if (Connections[j] == self)
+ break;
- for (i = 0, j = 0; i < NumConnections; i++)
+ if (j < NumConnections)
+ {
+ if (NumConnections > 1)
{
- if (Connections[i] == self)
+ Connection **new_array = calloc (NumConnections - 1,
+ sizeof (Connection *));
+
+ if (new_array)
{
- if (!new_array)
- Connections[i] = NULL;
+ int k;
+ for (i = 0, k = 0; i < NumConnections; i++)
+ {
+ if (i == j)
+ continue;
- continue;
- }
+ new_array[k++] = Connections[i];
+ }
- if (new_array)
- new_array[j++] = Connections[i];
+ free (Connections);
+ Connections = new_array;
+ NumConnections--;
+ } else
+ /* Failed to allocate memory. Just clear out the reference. */
+ Connections[j] = NULL;
}
-
- if (new_array) {
+ else
+ {
+ /* The only element is the one we no longer need. */
free (Connections);
- Connections = new_array;
- NumConnections--;
+ Connections = NULL;
+ NumConnections = 0;
}
}
- else
- {
- free (Connections);
- Connections = NULL;
- NumConnections = 0;
- }
if (self->http) {
debugprintf ("httpClose()\n");