ext/slim_attrib_ext.c in slim-attributes-0.5.0 vs ext/slim_attrib_ext.c in slim-attributes-0.6.0
- old
+ new
@@ -61,12 +61,19 @@
for (i=0; i < nr; i++) {
row = mysql_fetch_row(res); // get the row data and lengths from mysql
lengths = mysql_fetch_lengths(res);
for (s=j=0; j < nf; j++) s += lengths[j]; // s = total of lengths
pointers_space = ruby_xmalloc((nf + 1) * sizeof(char *) + s); // space for data pointers & data
+ if (!pointers_space) {
+ rb_raise(rb_eNoMemError, "out of memory");
+ }
p = *pointers_space = (char *)(pointers_space + nf + 1); // pointer to first data item
row_info_space = ruby_xcalloc(nf, 1); // space for flags for each column in this row
+ if (!row_info_space) {
+ ruby_xfree(pointers_space);
+ rb_raise(rb_eNoMemError, "out of memory");
+ }
for (j=0; j < nf; j++) {
len = (unsigned int)lengths[j];
if (len) {
memcpy(p, row[j], len); // copy row data in
p += len;
@@ -152,9 +159,10 @@
if (REAL_HASH_EXISTS) return rb_obj_dup(rb_ivar_get(obj, real_hash_id));
nf = RHASH(field_indexes)->tbl->num_entries;
row_info_space = ruby_xmalloc(nf); // dup needs its own set of flags
+ if (!row_info_space) rb_raise(rb_eNoMemError, "out of memory");
memcpy(row_info_space, GetCharPtr(rb_ivar_get(obj, row_info_id)), nf);
for (i=0; i < nf; i++) row_info_space[i] &= ~SLIM_IS_SET; // remove any set flags
frh = rb_class_new_instance(0, NULL, cRowHash); // make the new row data object
rb_ivar_set(frh, pointers_id, rb_ivar_get(obj, pointers_id));
rb_ivar_set(frh, row_info_id, Data_Wrap_Struct(cClass, 0, ruby_xfree, row_info_space));