summaryrefslogtreecommitdiff
path: root/databases/pgcluster/files/patch-pool_process_query.c
blob: e895ee978714f2c5187c4e0bb3ea15b0c1a17cdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--- src/pgcluster/pglb/pool_process_query.c.orig.orig	Wed Feb  4 23:35:56 2004
+++ src/pgcluster/pglb/pool_process_query.c	Wed Feb  4 23:37:29 2004
@@ -459,20 +459,31 @@
 
 			pool_write(frontend, &size, sizeof(int));
 			size = htonl(size) - 4;
-			buf = malloc(size);
-			if (buf == NULL)
+
+			/* read and send actual data only when size > 0 */
+			if (size > 0)
 			{
-				show_error("AsciiRow: out of memory");
-				return POOL_END;
+				buf = malloc(size);
+				if (buf == NULL)
+				{
+					show_error("AsciiRow: out of memory");
+					return POOL_END;
+				}
+				/* actual data */
+				if (pool_read(backend, buf, size) < 0)
+				{
+					free(buf);
+					return POOL_END;
+				}
+				pool_write(frontend, buf, size);
+				snprintf(msgbuf, Min(sizeof(msgbuf), size), "%s", buf);
+				free(buf);
+			}
+			else
+			{
+				*msgbuf = '\0';
 			}
-			/* actual data */
-			if (pool_read(backend, buf, size) < 0)
-				return POOL_END;
-
-			pool_write(frontend, buf, size);
-			snprintf(msgbuf, Min(sizeof(msgbuf), size), "%s", buf);
 			show_debug("AsciiRow: len:%d data: %s", size, msgbuf);
-			free(buf);
 		}
 		mask >>= 1;
 	}
@@ -728,10 +739,11 @@
 static POOL_STATUS EmptyQueryResponse(POOL_CONNECTION *frontend,
 									  POOL_CONNECTION *backend)
 {
+	char c;
+
 	/* set function name */
 	set_function("EmptyQueryResponse");
 
-	char c;
 	if (pool_read(backend, &c, sizeof(c)) < 0)
 		return POOL_END;