- ++num_mxrecs;
- if (mxrecs == NULL) {
- mxrecs = malloc(sizeof(struct mx));
- }
- else {
- mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) );
- }
+ // If there are no MX records for the domain, resolv will give us a single one with zero length.
+ // Make sure we only record actual MX records and not the blank.
+ if (strlen(expanded_buf) > 0) {
+ ++num_mxrecs;
+ if (mxrecs == NULL) {
+ mxrecs = malloc(sizeof(struct mx));
+ }
+ else {
+ mxrecs = realloc(mxrecs, (sizeof(struct mx) * num_mxrecs) );
+ }