Commits

Anonymous committed b2e1bc0

Changed all temporary allocations to use ALLOC_N (heap
allocation) rather than ALLOCA_N (stack allocation). In
particular, this allows PGconn#escape_string to accept
larger input strings without fear of exceeding the stack
size.

Thanks to Brett Neumeier.

Comments (0)

Files changed (1)

 
 	ptr = RSTRING_PTR(string);
 	len = RSTRING_LEN(string);
-	str = ALLOCA_N(char, len * 2 + 2 + 1);
+	str = ALLOC_N(char, len * 2 + 2 + 1);
 	str[j++] = '\'';
 	for(i = 0; i < len; i++) {
 		if(ptr[i] == '\'' || ptr[i] == '\\')
 	}
 	str[j++] = '\'';
 	result = rb_str_new(str, j);
+	free(str);
 	return result;
 }
 
 
 	Check_Type(string, T_STRING);
 
-	escaped = ALLOCA_N(char, RSTRING_LEN(string) * 2 + 1);
+	escaped = ALLOC_N(char, RSTRING_LEN(string) * 2 + 1);
 	if(CLASS_OF(self) == rb_cPGconn) {
 		size = PQescapeStringConn(get_pgconn(self), escaped, 
 			RSTRING_PTR(string), RSTRING_LEN(string), &error);
 			RSTRING_LEN(string));
 	}
 	result = rb_str_new(escaped, size);
+	free(escaped);
 	OBJ_INFECT(result, string);
 	return result;
 }